Search code examples
dockerdocker-volume

How can I mount a volume of files to a remote docker daemon?


I have a Docker image a which does some logic on a given set of files. When running locally, I start a as following:

docker run -v /home/Bradson/data:/data a

This does its job.

Now I want to run a on a remote Docker daemon:

DOCKER_HOST=tcp://remote_host:2375 docker run -v /home/Bradson/data:/data a

I am now getting the error that /data does not contain anything, most likely because /home/Bradson/data does not exist on the remote host.

How do I approach this? Should I first scp /home/Bradson/data to some directory on the remote host and refer to that director in the -v option? Is there a pure Docker approach?

Please note that I want to make /home/Bradson/data available at runtime, not during the build of a. Hence my usage of the -v option.


Solution

  • This is an answer to my own question.

    I found the following pure Docker approach. I was looking for a way to copy files to a volume directly, but that does not seem to be supported for some reason?

    You can copy files to a container however. So the following works:

     export DOCKER_HOST=tcp://remote_host:2375
     docker volume create data-volume
     docker create -v data-volume:/data --name helper busybox true
     docker cp /home/Bradson/data helper:/data
     docker rm helper
     docker run -v data-volume:/data a
    

    This is inspired by https://stackoverflow.com/a/37469637/10042924.