Skip to content

Instantly share code, notes, and snippets.

@Razuuu
Last active May 2, 2026 20:47
Show Gist options
  • Select an option

  • Save Razuuu/9dd3644ad4bd189ba54e21985b83dcb7 to your computer and use it in GitHub Desktop.

Select an option

Save Razuuu/9dd3644ad4bd189ba54e21985b83dcb7 to your computer and use it in GitHub Desktop.
How to save docker containers and the associated volumes

Works for docker compose files

First, stop all containers with

docker stop $(docker ps -a -q)

Save files

tar -cf docker.tar /var/lib/docker/volumes /opt/docker-containers/ # Or where the docker containers are

Move them to the new server via scp and run these commands.

tar -xf docker.tar
mkdir -p /var/lib/docker/
systemctl --now enable docker
mv var/lib/docker/volumes /var/lib/docker/
mv opt/docker-containers /opt/

# e.g /opt/docker-containers
for i in $(ls); do cd $i; docker compose up -d; cd ..; done

Go into the folder and run docker compose up. Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment