1

I need to backup a docker volume to a specific directory within another docker volume using Duplicity. So I need to run a command like this within the container performing the backup:

mkdir -p /backup/$backup-label
duplicity /target file:///backup/$backup-label

So I have created a docker image containing duplicity so I can run the above command with mapping the volume to be backed up to /target and the volume that stores the backup to /backup.

So my question is how to I pass $backup-label to the run command and how do I create the Entrypoint so that it makes sure that the correct directory structure exists prior to running duplicity as indicated above?

TIA, Ole

P.S. If I could run the container like this:

ole@MKI:~$ docker run --rm -it -v data-volume:/target -v backup-volume/label-for-backup:/backup duplicity-backup-image

That would solve it. But apparently docker does not allow the mapping of subdirectories within volumes. When I try I get the following message:

docker: Error response from daemon: create backup-volume/label-for-backup: "backup-volume/label-for-backup" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed.
Ole
  • 707
  • I ended up rewording this question a bit on stackoverflow and received an answer: http://stackoverflow.com/questions/37324541/referencing-a-dynamic-argument-in-the-docker-entrypoint – Ole May 19 '16 at 13:50

1 Answers1

1

A good solution is to use a shell script as CMD or ENTRYPOINT.

If you want to pass variables into the script, you can use -e to pass any environment variables to the script: docker run -e backup-label=somelabel. This option has the advantage that you can configure various areas without interpreting parameters. I suggest to also look into the ${variable:-} syntax.

In your case: docker run --rm -e backup-label=somelabel -it -v data-volume:/target -v backup-volume/label-for-backup:/backup duplicity-backup-image

The shell script (make sure it's executable):

#!/bin/sh 
mkdir -p /backup/$backup-label
duplicity /target file:///backup/$backup-label

(The other answer is maybe the more elegant solution for your use case. But this questions is slightly different, and the answer as well. So for reference. Also, as if your requirements should become more complicated...)

Dej
  • 212