What are containers?

On the official page of Docker, we can read: “Containers are an abstraction at the app layer that packages code and dependencies together” ( www.docker.com/resources/what-container ), but that is a very sophisticated definition. In more understandable words, a container is a piece of software that has all the minimal package code and dependencies necessary to run an application. This piece of software could run over software, in this case, the Docker engine.

What is Docker?

In 2013 Docker was launched as software for containerized applications. The Docker engine allows us to run different applications at the same time without any interference between there. Each application is isolated from the others, allowing the creation separates environments for each one. For example, we can have multiple containers running different versions of Ngixn or maybe OS. In the following image, we can appreciate this concept graphically.

Docker’s Basic Commands 

In this section, we are going to discuss the most common Docker commands used in a day to day administration tasks:

 

docker run.                                                              

 This command allows us to create and run a new container from an image.

Case of use:

 docker run nginx.

This command allows us to create and run a new container in base to the nginx image.

 Note: If the image is not locally accessible, we will download it from the docker hub.

 

docker run -d nginx.

This command allows you to create and run a new container in base to the nginx image, and that container will be run in the background (after the execution of the command, the shell prompt back).

 

docker run -d centos sleep 20.

This command allows you to create and run a new container in base to the centos image, and that container will be runned in the background (after the creation of the container, the command “sleep 20” will be executed). 

 

docker run -it nginx Bash.

This command allows you to create and run a new container in the interactive mode. The -it option specify the mode interactive (-i), and the tty (-t) with this combination can be attached to the prompt to the Bash (it specified in the last part of the command).

 

docker ps

This command allows us to list all the containers created.

Without any parameter (-a) just, listing the containers with the running state.

 

docker ps -a

This command allows us to list all the containers created. It does not matter the status.

 

docker images

This command allows us to list all the available images in the local repository.

 

docker start

This command allows us to start one or more stopped containers. 

 Note: we need to add the name or container Id at the end of the command (“docker start my_container”)

 

docker stop

This command allows us to stop one or more running containers. 

 Note: we need to add the name or container Id at the end of the command (“docker stop my_container”)

 

docker rm

This command allows us to remove (delete) one or more running/stopped containers. 

 Note: we need to add the name or container Id at the end of the command (“docker rm my_container”)

 

docker rmi

This command allows us to remove (delete) one or more images from the local repository. 

 Note: we need to add the name or container Id at the end of the command (“docker rmi my_image”)

 

 

For more information about this or others docker commands, visit the official documentation.

Docker run reference | Docker Documentation