Learning all about Docker: Create a Docker container

Just as Linux was an accidental result of Linus Torvalds, it was the same for Solomon Hykes. Solomon was trying to find a solution for developers to provide code that runs the same in both their development and production environments and this resulted in the creation of the Docker Container. In this tutorial, we’ll show you how you can start a Docker container on your , along with some additional tips and commands.

Today, Docker is the most popular software container platform.

docker explained

At a very basic level, Docker solves the problem associated with an application running on one platform but not another. Although present throughout the software development lifecycle, the primary use of the Docker Container is in deployment.

What are Docker containers?

Docker containers run instances of Docker images. Running an image creates a Docker container. Images provide a template that can be used for creating containers. These contain the information that is required to create containers. Images can be stored locally or remotely. If you need help installing Docker, check out our tutorials for or .

How to start a Docker container

Remember, before starting, you must access your VPS server with . Consult our if you have problems.

To list all the Dockers images on your system, you can use the command:

sudo docker images

If you want to display additional information, enter the following command at the command line:

sudo docker images –help

At this point, you don’t have any Docker images on your system, so the first thing to do is to pull one. To do so, first go to the . There you can find hundreds of Docker images.

See also  How to install WordPress locally (3 methods)

Continuing with the example, suppose we want to extract an Ubuntu image. You can browse the page of each image to see more details about it:

We can extract the image with the command:

docker pull

you can replace with hundreds of images found on Docker Hub like CentOS, , mariaDB, Python, etc.

The use of the option -q will list only the numerical IDs of the images available on your system.

sudo docker images -q

-F is the filter flag. If you wanted to list all the images that are not hung, tagged or referenced by a container, you would have to use the command:

sudo docker images -f “dangling=false”

Now that you know how to pull and locate an image to create a Docker container, you can get to work.

Here’s how to run an image; when you run an image, you actually create a container from that image. Continuing with the example, let’s run our Ubuntu image. To create a Docker container, use the command:

docker run

We will run the Ubuntu image. So the command will be:

docker run ubuntu

The container is created, but does not start.

To start the container, we use a command like this:

docker run –name MyContainer -it ubuntu bash

Here –name MyContainer is simply how we want to name the running process, whereas -it ubuntu bash indicates which container we are running.

Now we can open another terminal window, SSH into the server and run the command:

sudo docker ps -a

Open another terminal and issue the following command:

See also  How to Clear Browser Cache: Complete Guide

sudo docker start MyContainer

Now we can see that the container named MyContainer is running.

To stop the container use the following command:

sudo docker stop MyContainer

If you want to see the top process of a container, you can run the command:

docker top

It would look like this:

sudo docker top MyContainer

To view statistics for a container such as its CPU usage, memory usage, etc:

docker stats

Finally, if you want to cancel a Docker container:

sudo docker kill MyContainer

That’s it! You’re ready to create a Docker container and start using it!

concluding

Docker is an incredibly useful tool for any developer. The ability to seamlessly test, deploy, and develop applications is a utility that can speed up your workflow exponentially. In this tutorial, we show how to create a Docker container, along with some other commands that you will definitely find useful.

To learn more about a Docker container, we suggest you check out our other tutorials or the .

Deyi is a digital marketing enthusiast, with a background in web design, content creation, copywriting, and SEO. She is part of ‘s SEO & Localization team. In her free time, she likes to develop projects, read a book or watch a good movie.

Loading Facebook Comments ...
Loading Disqus Comments ...