DEV Community 👩‍💻👨‍💻

Cover image for Docker commands
Romero Dias
Romero Dias

Posted on • Updated on

Docker commands

Export/import image as .tar file

Save image to .tar file

 docker save -o <<filename>>.tar <<image-name>>:<<image-tag>>

Enter fullscreen mode Exit fullscreen mode

Delete images with simple search

docker rmi $(docker images | grep 'imagename') 
Enter fullscreen mode Exit fullscreen mode

Move the Docker directory

We gonna move the default docker directory "/var/lib/docker" to another.
Usually doing it when the docker host disk was not propertly dimensioned and we cannot increase de size.

Stop the docker service

service docker stop
Enter fullscreen mode Exit fullscreen mode

Verify if docker process is running yet

ps faux | grep docker --color
Enter fullscreen mode Exit fullscreen mode

Verify there is some files in the default docker directory

ls -la /var/lib/docker/
Enter fullscreen mode Exit fullscreen mode

Make a backup from docker directory

tar -zcC /var/lib docker > /dados/docker/bkp/var_lib_docker-backup-$(date +%s).tar.gz
Enter fullscreen mode Exit fullscreen mode

Move the directory /var/lib/docker to new home

mv /var/lib/docker /dados/docker
Enter fullscreen mode Exit fullscreen mode

Create a symlink

ln -s /dados/docker /var/lib/docker
Enter fullscreen mode Exit fullscreen mode

Verify symlink working well

ls -la /var/lib/docker
Enter fullscreen mode Exit fullscreen mode

Start the docker service

service docker start
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.