Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Backup Docker
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Backup Docker

Hi All,

I've just started "messing" with docker however i am unsure how/what to backup... i normally use Borgbase for backups

but how/what do i need to backup to be able to get docker working again in the event that the worst should happen?

thanks

chip

Comments

  • mount your volumes to host path and use your favorite backup tools.

    you can also payme $40 / hour and i will teach you good tricks.

    Thanked by 2chip mgcAna
  • @ehab said:
    mount your volumes to host path and use your favorite backup tools.

    you can also payme $40 / hour and i will teach you good tricks.

    So I can just backup the /var/lib/docker folder And all of its contents ?

    Thanks

  • @chip said:

    @ehab said:
    mount your volumes to host path and use your favorite backup tools.

    you can also payme $40 / hour and i will teach you good tricks.

    So I can just backup the /var/lib/docker folder And all of its contents ?

    Thanks

    No that's a bad idea maybe.

    Inside your docker-compose, specify where your data volumes are mounted, read the docker documentation on that.

    Then backup your data volumes.

    For example,
    if you keep all containers in ~/docker/container1, container2 etc. etc.
    then create ~/docker/container/data/ and tell your containers docker-compose to use ./data/ as the volume where the container stores it's data.

    Then you can easily back up each container's main directory, and backup docker-compose, any other files, including ./data inside that docker container's folder.

  • For example:

    # Wordpress
    wordpress:
    depends_on:
    - database
    image: wordpress:php8.1-fpm-alpine
    container_name: wordpress
    restart: always
    user: "root:root"
    env_file:
    - .env
    environment:
    - WORDPRESS_DB_HOST=database:3306
    - WORDPRESS_DB_USER=$MYSQL_USER
    - WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
    - WORDPRESS_DB_NAME=blog_wp
    volumes:
    - ./php.ini:/usr/local/etc/php/conf.d/custom.ini
    - ./wordpress:/var/www/html
    networks:
    - blog-network

    ** This is not a complete docker-compose file but to show you.

    Thanks!

  • You can use this for named volumes https://docs.docker.com/storage/volumes/#back-up-restore-or-migrate-data-volumes

    Or use bind mounts https://docs.docker.com/storage/bind-mounts/ which will expose the data to your host system and you can use whatever you are used to.

    Regardless if you use either of the above methods, if you are backing up a database, best way is to dump it using the db system dump tool and compress it before sending to your backup destination.

    You need to think of docker containers as ephemeral things that can be killed at any time and easy to get back up.

  • vsys_hostvsys_host Member, Patron Provider

    It makes sense for you to back up only the data of volumes that are connected from the host machine, because root files system not changing inside docker. You can find them by doing docker inspect, by default volumes are located in /var/lib/docker/volumes/.

  • I keep a folder like /data/docker for storing docker data. For each container used in docker, a sub folder is created like /data/docker/nginx-proxy-manager for example. Whenever the docker container allows, the container's config/data directories are mounted in the created folder on the host. Like /data/docker/nginx-proxy-manager/data. Also a file install.sh is kept in that folder which contains the command used to create that container. Sometimes a file run.sh is also kept which contains the command used to start that container, in cases where it uses any special parameters or options. And I will backup this /data/docker folder like other folders with rsync/borg/restic. If somehow the container gets corrupted or messed up, remove the corrupted container, copy over the container's folder from backup and run its install.sh. Has worked for me so far, though I use docker only for personal stuff like self-hosting apps and checking new apps.

    Thanked by 2dev077 chip
  • On my local machines I have docker setup with the data directory to an nfs shared external drive. Occasionally I'll use a simple rsync to another drive for redundancy.

    On VPS I'm using the image: offen/docker-volume-backup found on dockerhub. Setup in the stack compose file to backup the named volumes for services with relevant data. It runs a cron job and sends a tar file to my offsite storage via ssh.
    It can be configured to stop/restart containers so you don't end up with corrupt files.

    For more static data (eg. static website and config files that I use bind volumes for, vps /etc files, etc.) I use a manual rsync. That serves as a dual purpose backup copy since I can just make config changes to my local files and send updates to the server.

    I use portainer and since it doesn't have a feature to backup such I just keep a separate copy of my compose files and any custom image Dockerfiles. Hmmm... maybe I should keep a backup my portainer volumes. In any case, all images and containers are considered disposable (or easily recreated) so no need to backup them up.

Sign In or Register to comment.