How to Work with Docker Containers Using the Command Line
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.
1 | 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:
1 | docker container stop <ID> |
For example:
1 | docker container stop 739037a911e0 |
Once a container is stopped, you can view it by using the docker container ls -a
command:
1 | docker container ls -a |
Here is an example of the output:
To remove a stopped container, you can use the docker container rm
command:
1 | docker container rm <ID> |
For example:
1 | docker container rm 739037a911e0 |
The docker inspect
command allows you to gather detailed information about a specific container:
1 | docker inspect <ID> |
For example:
1 | docker inspect 739037a911e0 |
Another helpful command is docker info
, which provides comprehensive information about your Docker installation, including the number of containers and images:
1 | 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.
tags: [“Docker”, “containers”, “CLI”, “command line”, “Docker Desktop”, “images”]