Let's Make a Docker Image [Part 2]

Posted by Miloš Đorđević on Jul 15, 2020 12:18:52 PM
Find me on:

If you have been searching for information about Docker, and you’ve ran into this blog - today must be your lucky day! Continue reading, because we will play a bit with Docker, images, and containers, providing you with a step by step, hands-on experience. If you want to follow the explained steps yourself, please install Docker before you move on.

In our previous blog post about Docker, you've already learned what Docker is and what are its main benefits. Before we begin, I am sharing with you the installation guide for Windows, Mac and Linux. I will use my Windows, but if you use any other supported OS, you’ll have the same or similar experience. Open your terminal (for Windows users, Command Prompt or PowerShell) - and let the games begin.


Our first Docker command:

docker info


The docker info command shows us information about the Docker installation, kernel version, number of containers, and images. If you haven’t used Docker on your machine, you will see the same numbers for containers and images like me - zero.

A Docker image is a file comprised of multiple layers, including a source code or binary, libraries, dependencies, tools, and other things needed to run the application.

A Docker container is a standardized, runnable instance of a Docker image, which combines the application code with all dependencies required to run the code in any environment. Docker stores all images we build in the registry for us. There are a lot of different registries, but the most famous one is called Docker hub.

Docker Hub is the world's largest library and community for container images. Here you can find images from various software vendors, open-source projects and the community - and you can start using them now.  


Let's get the first image using the following command:

docker pull ubuntu



Docker pull command will download the image ubuntu, pulling it from the public registry.

docker images



The Docker images command will show us all our images. Let's run the ubuntu image:

docker run -it ubuntu


This command will run ubuntu container base on the ubuntu image and open ubuntu's terminal. For interactive processes (such as a terminal), you must use -i -t together to allocate a tty for the container process. -i -t is often written shortened: -it.

Now, we have ubuntu running as a Docker container.


Exit the container with a simple exit command:

docker ps -a


The docker ps -a (-all) command shows us a list of all containers, while the default shows just those that are running. We see a finished container under the id 79c14f4eb725 from the ubuntu image, so we will start that container again using the command:

docker start 79


Notice we did not use the whole id of the container - it is enough to use only the first part, that unambiguously defines it. In the same way, we can use a command to stop the containers:

docker stop 79


Obviously, running containers takes up some resources. We can use the docker stats command to check into the usage of resources:

docker stats


If we want to remove a container, we use docker rm command, like this:

docker rm 79


Congratulations on your first hands-on experience with Docker!


Do you want to dive deeper into how to create your own Docker image? In the upcoming blog post, we will create a Docker file and build our first Docker image.

If you're interested in the next blog on how to use Docker, leave your comment below or subscribe here.


Topics: Docker, DockerHub, Containers