Hello everyone!, Today we are going to look at step by step process of creating and running a docker container.
Docker is a software platform that lets you build, test and deploy application very quickly. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly Using Docker an application can be easily deployed and scaled in any environment. Docker provides the ability to package and run an application in a loosely isolated environment called a container. Containers are lightweight and contain everything needed to run the application, so you do not need to rely on what is currently installed on the host machine.
Docker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and distributing your Docker containers which may or may not run on same system as client.
To create docker container from image we make use of docker create command along with the image.
An image is a read-only template with instructions for creating a Docker container. A container is a runnable instance of an image.
docker create nginx:alpine
This will create container with nginx:alpine image and the container will have some random name assign to it. If the images are not present locally then it will pull it from registry.
We can assign custom name to docker using --name
docker create --name myNginx nginx:alpine
This will create nginx docker container with name myNginx. But to access our container from our computer we need to port forward it to specific port using -p
docker create --name myNginx -p 80:80 -d nginx:alpine
Now we can access our container myNginx on port 8080.
Docker start command will start docker container and status of container will change from Created to Running.
Docker ps will list all the running containers and using -a will list all containers created in the machine.
docker ps -a
You can see our myNginx container created and currently in running state.
Docker images command will list down all the images.
docker images -a
Docker stop command will stop the container and you can see the status turned to Exited state.
And our docker ps command shows the status as Exited
Docker rm command will remove the specific container permanently
You can check using docker ps command that container is removed from machine.
That's it for today, until next time Happy Coding!..