skip to Main Content

I’ve been trying to accomplish migrating a volume from one container to the same container on a different host, just by testing out the method in the Docker docs: Restore Volume from Backup. However, the project I am working on starts the container using docker-compose instead of docker run. Anyone know if I can change the .yaml file somehow to decompress a tarball (similar to the docker run method)?

The docker run command for restoring from a backup looks like this:

docker run --rm --volumes-from dbstore2 -v $(pwd):/backup ubuntu bash -c "cd /dbdata && tar xvf /backup/backup.tar --strip 1"

2

Answers


  1. Chosen as BEST ANSWER

    So, I followed the docs linked in my question. The reason it wasn't working originally is because I needed to double check that the original volume AND container were removed before mounting the backup volume.

    Essentially,

    1. Backup volume as per the Docker documentation
    2. Remove original container and volume
    3. Restore volume as per documentation

  2. If you can decompress the tarball file you can use this in your docker-compose.yaml file

     mysql:
          image: mysql:5.7
          hostname: mysql
          container_name: mysql
          restart: always
          expose:
              - '3306'
          ports:
              - '3306:3306'
          environment:
              - 'MYSQL_ROOT_PASSWORD=something'
          volumes:
              - mysql_db:/var/lib/mysql
              - ./your-backup.sql-file:/docker-entrypoint-initdb.d 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search