Image Handling
docker image list | list downloaded images |
docker rmi image_name | delete image |
Administration
docker system df | show docker disk usage |
docker system prune | free space – remove stopped containers, images, cache |
systemctl restart docker.service | restarts the docker service (and all your container) |
ss -tulpn | check if docker containers listen to any port |
docker exec contaienr_id cat /etc/hosts or docker inspect -f ‘{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}’ contaienr_id | check container ip address |
Container Handling
docker ps | list running containers |
docker ps -a | list all the docker containers (running and stopped) |
docker stop container_id | stop container |
docker rm container_id | delete stopped container |
docker update –restart=unless-stopped container_id | make sure container re-start, unless manually stopped |
docker run -l debug container_id | run container with log |
docker logs -f container_id | display log |
docker exec -it container_id /bin/sh | open a shell in the running container |
docker commit container_id user/test_image | this command saves modified container state into a new image user/test_image |
docker run -ti –entrypoint=sh user/test_image | run with a different entrypoint |
docker run –volume-driver=nfs container_id | mount NFS share |
Docker Compose
docker-compose -f ~/docker/docker-compose.yml up -d | The -d option daemonizes it in the background |
docker-compose -f ~/docker/docker-compose.yml down | completely stop and remove containers, images, volumes, and networks (go back to how it was before running docker compose file) |
docker-compose -f ~/docker/docker-compose.yml pull | Pull latest images |
docker-compose logs container_id | check real-time logs |
docker-compose stop container_id | stops a running container |
docker-compose config | test your.env file which is used for variable substitution in the docker-compose.yaml |