In the first part of the series, we learned – what is docker and familiarised ourselves with docker terminology. We also saw why docker is useful for developers. Now, let’s get started by creating our first application.
We need to have docker installed and running on our system to get started. You can install it from here: Get Docker
I am using the Docker Desktop for Mac but the OS should definitely not matter 🙂
Once Docker is installed and running on your system, we can test if it’s up by using the following easy command.
This would provide you with detailed information about the docker version installed in your system.
Pulling an Image from DockerHub
Go to your terminal and type in the command
docker pull hello-world
and it would return something like this
So what happened?
When we told Docker to pull ‘hello-world’, the Docker client connected the Docker daemon (also called as the Docker server) which in turned contacted the DockerHub.
DockerHub is a centralised repository for finding and sharing container and images.
It then searched if it contained any library named ‘hello-world’. It was able to find it.
It then took the latest version of ‘hello-world’ and downloaded it into our system, also creating a unique id for it.
We now have our first image. The following command would list down all the images you have downloaded in the system.
I have one image called ‘hello-world’ and can see all its details. It has its unique image id and is 13.3 kb in size. Pretty neat.
Running a container
Let’s try running this image as a container. Use this command in the terminal
docker run hello-world
This turned our image into an executable container and we have an output. We created our first hello-world application on Docker!
You can see all the running containers by this command
What? This list is blank. This is because a when you use docker run, the container exits as soon as the program inside it terminates. In this case, the container only had one task – to output the text. It did that task and exited, so we have no running containers at the moment. You can use other commands to manually start or stop conatiners but we will get to it in the next post.
You can see a list of containers despite its running states by
docker ps -a
There it is – our container id, the image with which it is associated and status which shows it has been exited a minute ago.
In this post, we installed Docker, pulled an image from the DockerHub and run our first container. This was easy, isn’t it? Now let’s move on to creating our own image and uploading it onto DockerHub.
Please subscribe, you’ll only be notified of new posts 🙂