bashdockerdockerfilequotingduplicity-backup

Referencing a dynamic argument in the Docker Entrypoint


I want to run a docker container like this:

docker run --rm -it -v volume1:/target -v volume2:/backup duplicity-image backup-label

This would cause the following Entrypoint do get executed:

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

So my question is how do I structure the ENTRYPOINT such that it can resolve the $backup-label and how do I pass the backup-label in ... Do I need single quotes around it ... a dash in front of it ...?


Solution

  • When you have an ENTRYPOINT script in your image, that script will receive any arguments passed after the image on the docker run command line. That is, if you have:

    ENTRYPOINT /path/to/my/script.sh
    

    And you run:

    docker run myimage one two three
    

    Your ENTRYPOINT script will be called like:

    /path/to/my/script.sh one two three
    

    From that point on, it's just like writing any other shell script that takes arguments:

    #!/bin/sh
    
    backup_label=$1
    duplicity /target file:///backup/$backup_label