Skip to content

Docker

1. Grant Permission

sudo groupadd docker
#sudo gpasswd -a ${USER} docker
sudo usermod -aG docker $USER
sudo service docker restart

2. Clean

# untaggged and unused
docker image prune
# unused
docker image prune -a
# filter
docker image prune -a --filter "until=24h"
# delete stopped containers
docker container prune
# rm exited containers
docker rm $(docker ps -a -f status=exited -q)
# clean images
docker rmi $(docker images --filter "dangling=true" -q --no-trunc)

3. Build

docker build --network host /dir/contains/dockerfile

docker tag img name:tag

docker commit container name:tag

4. Run

docker run --name test -h hostname --network host -itd -v /abs/path:/abs/path imgname:tag

docker exec -it test bash

5. Saving

5.1 Export/Import

docker export <container_id> > container.tar
docker import /path/to/container.tar

Export is taking a snapshot of the container. All informations about history and layers will be lost!

5.2 Save/Load

docker save container_id > container.tar
docker save myimage:latest | gzip > myimage_latest.tar.gz
docker load < hangge_server.tar

Informations about layers and history will be saved and loaded!

6. Restart without killing containers

https://stackoverflow.com/questions/63434189/does-restarting-docker-service-kills-all-containers


Last update: December 21, 2023
Authors: Co1lin (40.85%), Co1lin (59.15%)