Configuring Duplicati on Docker with Google Suite

Recently I’ve been digging into Docker and Containerization, and wanted to share a workflow I’ve adapted from LinuxServer. Docker containerization allows anyone to easily share environments to eliminate the “it worked/didn’t work on my machine!” conversation, and speeds up developer time by eliminating time-consuming setup steps. In this example, we will set up a preconfigured Docker container running Duplicati and hook it up to Google Drive for seamless, free, cloud-hosted backups.

I recently set up a Google Suite account for the low, low price of $10/user/month that allows for unlimited file storage. I have been porting my media server over to Google Suite with Plex Drive, and figured since I wasn’t running out of storage space on the volume soon, I would set up a back up service as well.

I am choosing Duplicati for the backup for a few reasons, mostly that it is free, runs only on your local machine, and is very extensible should Google decide to enforce their user agreements as stated below and the back up location would need changed.

The first step is to get started on Google, selecting the Business edition for $10 per user per month. You don’t actually need a business to get started, and the license states that you need 5 users for unlimited storage, but from my experience Google doesn’t enforce that limit at the time I wrote this (July 2017).

Next step you need to configure Docker for your local machine, and you can find instructions on how to do that on Docker’s website. All you need for this tutorial is the basic Docker App installation (I am writing this for macOS only).

Okay, now that the environment setup is complete, we can start backing up our files.

First thing we need to do is to copy LinuxServer’s Duplicati container image from the Docker Hub, using this command in the terminal:

docker pull linuxserver/duplicati:latest

This will pull the preconfigured Duplicati container from Docker Hub. I am not a systems designer and don’t want to configure my own container, and LinuxServer pushes multiple containers for home server technologies on a regular basis.

Next, we need to create the container:

docker create --name=duplicati --restart always -v <LOCAL PATH>:/source -v <LOCAL CONFIG PATH>:/config -p 8200:8200 linuxserver/duplicati

This command does a few things.

  1. It creates the container on your local machine
  2. --name=duplicati names the container “duplicati”
  3. --restart always ensures that the docker container will start every time you boot your machine
  4. -v <LOCAL PATH>:/source mounts the local path given within the <...> on the docker container
  5. -v <LOCAL CONFIG PATH>:/config ensures that your configuration files (i.e. jobs) will persist. Place this file somewhere you will remember it and won’t accidentally delete it.
  6. -p 8200:8200 exposes port 8200 from the container to the local machine
  7. linuxserver/duplicati references the image you created above.

Notes on the commands:

  • The Docker daemon (Docker App you installed) will keep a list of all the docker containers on the system and their restart policies, so adding the --restart always flag when creating the container will ensure that the backup service starts whenever you boot your machine. (Assuming you have set Docker to start when your machine starts up)
  • Since the container we’re pulling from is a blank image and doesn’t have any information on your local filesystem, Docker gives us the -v flag when creating containers to make sure that your local filesystem is mounted on the container volume. When we add -v <LOCAL PATH> and -v <LOCAL CONFIG PATH>, it mounts those paths into our container for the container to use. If we don’t specify a config path, Duplicati won’t persist jobs between restarts.

Once you’ve created the container, you start it on your local machine with this command:

docker start duplicati

This will mount the container and start it on your local machine. You can verify that it’s set up correctly by visiting localhost:8200 in your web browser. You should see this screen:

Once you’ve verified it is running, you can verify that the local path from #3 above was properly mounted by running a shell inside the container:

$> docker exec -it duplicati /bin/bash
$> ls /source

If you see your local data, then you’ve done it correctly. The remainder of the tutorial is Duplicati configuration, so if you want to skip the rest and figure it out yourself, feel free. (It’s pretty self explanatory).

Now, we configure a new backup job on Duplicati by selecting “Add Backup”:

Name the backup and create a password: **NOTE** if you forget this password, you won’t be able to access the volume, so make sure you remember it. I use 1Password and just created a simple password combination with the name “My Photos” and a tag “duplicati”.

Next, configure the cloud storage. Since we’re using Google Drive, select Google Drive from the dropdown.

Name the drive, and click through to authorize the Duplicati OAuth service:

You will see these screens:

I like to test the connection, always.

Now you’ll configure where Duplicati will get your files. This is a good example of how Docker handles mounted paths from your local machine. Remember how we added the -v <LOCAL PATH>:/source flag to the docker create command above? It will mount the local path you input in a folder called source in the root path. You can configure this to go anywhere on your local machine or on the container. Here’s where it shows up in your container as described:

Unless you’re uploading configuration files or system files, there’s no reason to upload hidden, system, or temporary files.

Select the files/folders you want backed up, and then configure the back up job. For this example (photos backup), I chose to run the job once per month.

Since we’re using Google Suite with unlimited storage, you can keep unlimited copies of your files! This may not be necessary for your photos folder (I ended up setting this up to store 3 months of backups, another option), but it could be very useful for other applications of this backup strategy.

Once you save the backup job, you can click to the home page and see your new backup!

You can run it now, or wait until the next scheduled backup time. It may take a while to upload the first batch of photos (I have a lot of photos, mostly from my wedding…) but it will be faster on subsequent backups.

*Shameless self promotion* I am currently available for contract and full-time work in Atlanta, so get in touch with me at nick@ni3t.com if you have an opportunity available!