Is it possible to make a backup of all my running docker containers and /or the commands used to create them to migrate to another server? ... if so how?
Docker was made to be portable, look up the networking and volumes attached and you'll be good to go on starting up new containers. Make sure to copy images over if you built them yourself.
create/use a docker private registry push all of them to private registry, pull them from new node. (remember that shared mounts files won't be included)
or manual file (image) transfer.
#!/bin/bash
# Get a list of all running container IDs
container_ids=$(docker ps -q)
# Iterate through each container
for container_id in $container_ids; do
# Generate a unique image name based on the container ID
new_image_name="saved_image_${container_id}"
# Commit the container to a new image
docker commit "$container_id" "$new_image_name"
echo "Saved container $container_id as $new_image_name"
done
Comments
sounds like docker compose?
Docker was made to be portable, look up the networking and volumes attached and you'll be good to go on starting up new containers. Make sure to copy images over if you built them yourself.
https://github.com/Red5d/docker-autocompose
i have some notes from the past when backing up / restoring containers.
-to backup-
docker run --rm --volumes-from portainer -v $(pwd):/backup busybox tar cvfz /backup/backup.tar /data
-to restore-
docker run --rm --volumes-from portainer -v $(pwd):/backup busybox sh -c "cd /data && tar xvf /backup/backup.tar --strip 1"
hopefully this is helpful!
create/use a docker private registry push all of them to private registry, pull them from new node. (remember that shared mounts files won't be included)
or manual file (image) transfer.
#!/bin/bash # Get a list of all running container IDs container_ids=$(docker ps -q) # Iterate through each container for container_id in $container_ids; do # Generate a unique image name based on the container ID new_image_name="saved_image_${container_id}" # Commit the container to a new image docker commit "$container_id" "$new_image_name" echo "Saved container $container_id as $new_image_name" done