Running first Container
docker run is the command to create and run our containers. So let’s run our first container from an image just to test if everything is working fine in order.
ubuntu@ip-172-31-36-213:~$ docker run hello-world
And we are set to proceed ahead
This container will just print the message and would be dead. If we wish to see the processes running, docker ps is the command. However docker ps would not show us anything as the container would be in an exited state. So as to see the container we need to execute docker ps -a
A lot of new terms. Let’s break them down one by one.
Docker Image
- A stopped container like a vm image/ archived version of it
- Image consists of multiple layers. For example when we do apt install git, it adds a layer. Similarly an image consists of multiple layers
- An app will be bundled in an image
- Containers runs from an image
- Docker images are stored at Docker Hub
- Docker Hub is a registry for Docker images
- Images are called as Repositories in registries
Docker Registries
- Storage for docker images
- DockerHub is the default registry
- Cloud based registries – dockerhub, GCR(Google container registry), Amazon ECR
- In house of Local Registries – Nexus 3, JFrog Artifactory, DTR(Docker Trusted Registry)
Practical Stuff
Let’s download nginx and jenkins image.
docker pull nginx:tagname (if you want to download a specific version, If tagname is not provided docker will pick up the latest tag as default )
docker pull jenkins
Now let’s create a container from the nginx image
docker run --name {container name} -d nginx
-d => detached mode i.e container will run in the background
By default nginx runs on port 80. And if I want to access it from my host machine I can do that. Each container will have its own virtual network, which means every container would have a seperate IP. Let’s fetch the IP of the container created and access nginx running on container via host machine. To fetch the details about the container/image we can use docker inspect command.
docker inspect <container-id>
Now let’s connect to container via host machine