Commands

This is a list of useful docker commands.

Add server to portainer

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

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

Build image

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.

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

Monitor stats

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

docker stats --no-stream

Get container's IP

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

Remove unused images

You can remove all unused images using the following command:

Kill all containers

You can kill all running containers using the following command:

Delete all stopped containers

You can delete all stopped containers using the following command:

Delete all images

You can delete all images using the following command:

Delete all volumes

You can delete all volumes using the following command:

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

Last updated