Running Containers the Simple-Way

Aman Arham
3 min readJul 13, 2020

Now that you have understood what Docker is and what Containers do in the background of all software development, it is time to create your first ever container. This is probably the most anticipated blog in regards to Docker and Containers. With all of the components ready(Docker on your PC and terminal and a Docker Hub account) it is time!

Understanding Images

Wait. We have one more thing to go over. Before creating the container, we must understand Images and how they correlate to creating Docker Containers. All containers are composed of Images. These images are retrieved from the Docker Hub registry and are used to execute code for the Container. Here is a link to the many different Docker Images available on the Docker Hub Page:

Creating a Container

Now it is time to create a container. With everything installed and up and running, go into your terminal. You will have to enter a command that will log you into your Docker Hub page so that the images can be used. Here is the command:

docker login

Enter your credentials into the terminal console. For this demonstration, we will be using the NGINX image. Because we are utilizing this image, we will type this command into the terminal/console:

docker pull nginx

This command will allow us to pull or get the image from the Docker Hub repository and it will store it in the terminal. Use this command to view the images that are pulled:

docker images

Now that we have the image, we can use a command to run the image which will create the container. That command is:

docker run nginx

When this runs, you will see a blank screen similar to this:

Don’t worry the container has been created. In order to see it, click the control button and c at the same time and you will come back to the default console. At the console, type this command:

docker ps -a

What this command does is that it loads up all the container that are running. You should be able to see the NGINX container running:

If you would like to add some recognition and update that the container has been created, use this command instead of docker run nginx

docker run nginx echo “the container has been created”

When this command is entered, the the statement, which is in the quotes, will be printed to indicate that the container has successfully run. The echo functions allows for this to happen. In the end, it should look something like this:

A reminder that anything can be put in the quotes. It is only printed to indicate that the container was successfully created.

And Voila!

Congratulations! You have created your first Docker Container running with a NGINX image that you got from the Docker Hub. They are many other ways to create and run a Docker Container, such as using a DockerFile, but this is the main and simple way to do it. I will go over the DockerFile in my next blog. Until then, Aman Arham out!

--

--

Aman Arham

Senior at Rick Reedy High School and aspiring Data Scientist; Writer for Better Programming.