How To Run A Docker Container In Linux?

Containerization is a process that encapsulates an application in a container with its own operating environment. It is a kind of lightweight alternative to full machine virtualization.

The benefit of using the containers is that you can run the applications on any physical machine without worrying about dependencies.

Ahead in this article, we will discuss docker containers and running them on Linux.

Docker containers

A docker container contains an application with all parts of it needed such as libraries and other dependencies and ships it as one package. Instead of using dedicated resources like virtual machines, it shares the kernel and other resources of a system.

Before you run any docker command you need to install docker in your system.

How to download the docker images

A docker image is an immutable file that is essentially a snapshot of a container. You can create an image using the build command, and it produces a container when started with the run command.

So first you need to download an image before you run the container. You can search and download an image from the docker hub by using the following commands –

To search an image run –

sudo docker search ubuntu

This will display the list of images available with the name Ubuntu in the docker hub. Here you can identify the image that you want to download.

Now execute the following command to download the image of ubuntu –

sudo docker pull ubuntu

How to run a docker container

You can check the downloaded docker images by using the following command –

sudo docker images

Now you can run a container by using –

sudo docker run -it ubuntu

How to display running containers

To display the list of running containers in your system use –

sudo docker ps

OR if you want to display the list of all the containers then use –

sudo docker ps -a

How to start/stop a container

To start a container in interactive mode use –

sudo docker start -i container_ID

For example –

sudo docker start -i ubuntu

Similarly, you can use the following command to stop a container –

sudo docker stop container_ID


Ok, that’s all for now. To know more about the options and commands that can be used with the docker, run docker command without any argument. You can also display the commands by executing man docker in your terminal.

Leave a Comment