Skip to content

Docker commands

Using this command you’ll spin up a portainer agent and then you can connect it in the portainer UI using the IP and port 9001

Terminal window
docker run -d \
-p 9001:9001 \
--name portainer_agent \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/lib/docker/volumes:/var/lib/docker/volumes \
-v /:/host \
portainer/agent:2.21.3

You can build a docker image if you have a Dockerfile in the current directory. The image will be tagged as image:x.x.x and you can change it to whatever you want.

Terminal window
docker build -t image:x.x.x .

You can monitor the stats of a container using the following command:

Terminal window
docker stats --no-stream

You can get the IP of a container using the following command:

Terminal window
docker inspect -f "{{.NetworkSettings.IPAddress}}" <container_name>

You can remove all unused images using the following command:

Terminal window
docker image prune -a

You can kill all running containers using the following command:

Terminal window
docker kill $(docker ps -q)

You can delete all stopped containers using the following command:

Terminal window
docker rm $(docker ps -a -q)

You can delete all images using the following command:

Terminal window
docker rmi $(docker images -q)

You can delete all volumes using the following command:

Terminal window
docker volume rm $(docker volume ls -q)

This browser does not support PDFs. Please download the PDF to view it: Download PDF.