简体   繁体   中英

Restoring a volume from backup using docker-compose

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"

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 

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM