Docker containers are a powerful tool for managing and running applications. While the Docker Desktop application provides a graphical interface to work with containers easily, you can also utilize the command line interface (CLI) commands for more flexibility and control.
To list the currently running containers, you can use the docker ps
command. Alternatively, you can run docker container ls
for the same result.
docker ps
Here is an example output of the command:
In this case, the output shows a container named node-app
with an ID of 739037a911e0
. The container was created 4 minutes ago and has been up for the same duration. Additionally, the port 80 on the host machine is mapped to the container’s port 3000 using the TCP protocol.
If you know the container’s ID, you can stop it by running the following command:
docker container stop <ID>
For example:
docker container stop 739037a911e0
Once a container is stopped, you can view it by using the docker container ls -a
command:
docker container ls -a
Here is an example of the output:
To remove a stopped container, you can use the docker container rm
command:
docker container rm <ID>
For example:
docker container rm 739037a911e0
The docker inspect
command allows you to gather detailed information about a specific container:
docker inspect <ID>
For example:
docker inspect 739037a911e0
Another helpful command is docker info
, which provides comprehensive information about your Docker installation, including the number of containers and images:
docker info
Here is an output example:
In conclusion, using the Docker CLI commands can enhance your container management experience. By leveraging these commands, you can easily monitor, stop, remove, and inspect containers, as well as gather essential information about your Docker installation.