Docker commands

romerodias

Romero Dias

Posted on March 30, 2020

Docker commands

Stop all containers

 docker stop $(docker ps -a -q)
Enter fullscreen mode Exit fullscreen mode

Delete images

  • By image name
docker rmi $(docker images  'imagename' -a -q) 
Enter fullscreen mode Exit fullscreen mode
  • Untagged images
docker rmi $(docker images -f "dangling=true" -q) 
Enter fullscreen mode Exit fullscreen mode

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
  • Load/import image
docker load -i <filename>.tar
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
💖 💪 🙅 🚩
romerodias
Romero Dias

Posted on March 30, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related