Docker Basics
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:
docker inspect -f "{{.NetworkSettings.IPAddress}}" <container_name>
Remove unused images
You can remove all unused images using the following command:
docker image prune -a
Kill all containers
You can kill all running containers using the following command:
docker kill $(docker ps -q)
Delete all stopped containers
You can delete all stopped containers using the following command:
docker rm $(docker ps -a -q)
Delete all images
You can delete all images using the following command:
docker rmi $(docker images -q)
Delete all volumes
You can delete all volumes using the following command:
docker volume rm $(docker volume ls -q)