managing containers
Managing containers can be a hassle and quite time consuming without some easy tweaks. I also recommend assigning these commands to an alias in your ~/.bashrc making it available and convenient in your home environment and remote shells.
stop containers
docker stop $(docker ps -a -q)
delete downloaded Images
docker rmi -f $(docker images -q)
delete stopped containers
docker rm $(docker ps -a -q)
delete dangling images
docker rmi $(docker images -q)
live log containers
docker-compose logs --follow
live log specific containers
docker logs -ft dc --follow
bash into container
docker exec -ti pihole /bin/bash
inspect specific container
docker inspect [container-id]
mount volumes
docker run -it -v pihole-etc:/mnt/ ubuntu bash
save running container as image
docker commit -m “commit message” -a “author” container_name username/image_name:tag
debian
docker run -d --name debian -it debian
alpine
docker run -it alpine /bin/sh
Automating docker with scripts
kill & delete stopped containers, images & volumes
Simple task for removing running things.
#!/usr/bin/env bash
docker-compose down
docker kill $(docker ps -q)
docker rm $(docker ps -a -q)
docker system prune -f
docker image prune -f
docker volume prune -f
docker ps
compose kill, delete containers, images and volumes
This snippet also includes compose down and up rather than restart, since i was running in some issues using restart option with stateless containers.
#!/usr/bin/env bash
docker-compose down
docker kill $(docker ps -q)
docker rm $(docker ps -a -q)
docker system prune -f
docker image prune -f
docker volume prune -f
docker rmi -f $(docker images -q)
docker-compose pull
docker-compose down
docker-compose up
docker ps
docker-compose ps
docker-compose logs --follow
compose down up as a service
no brainer for restarting projects and keep them as a service.
#!/usr/bin/env bash
docker-compose pull
docker-compose down
docker-compose pull
docker-compose up -d --build
docker ps
docker-compose ps