Containers are instances of Docker images that can be run using the Docker run command. The basic purpose of Docker is to run containers. Let’s discuss how to work with containers.
Running of containers is managed with the Docker run command. To run a container in an interactive mode, first launch the Docker container.
sudo docker run –it centos /bin/bash
Then hit Crtl+p and you will return to your OS shell.
You will then be running in the instance of the CentOS system on the Ubuntu server.
One can list all of the containers on the machine via the docker ps command. This command is used to return the currently running containers.
docker ps
docker ps
None
The output will show the currently running containers.
sudo docker ps
When we run the above command, it will produce the following result −
Let’s see some more variations of the docker ps command.
This command is used to list all of the containers on the system
docker ps -a
─a − It tells the docker ps command to list all of the containers on the system.
The output will show all containers.
sudo docker ps -a
When we run the above command, it will produce the following result −
With this command, you can see all the commands that were run with an image via a container.
docker history ImageID
ImageID − This is the Image ID for which you want to see all the commands that were run against it.
The output will show all the commands run against that image.
sudo docker history centos
The above command will show all the commands that were run against the centos image.
When we run the above command, it will produce the following result −