32

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.

Bradson
  • 615
  • 1
  • 6
  • 9
  • This answer here https://stackoverflow.com/a/55683656/1315009 fits your question, although the question is not an exact duplicate. The other question asks for a "generic" copy while the particular answer of the triad `create`+`cp`+`rm` does effectively work with remote volumes, which was your concern (and mine). – Xavi Montero May 04 '20 at 09:25

1 Answers1

29

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.

Greg Dubicki
  • 5,983
  • 3
  • 55
  • 68
Bradson
  • 615
  • 1
  • 6
  • 9
  • 2
    im also looking for a solution to this issue. one that makes the local directory to the remote host right from docker-compose where you set the volume to /home/dev:/remote/dev – PICTD.RUFY Aug 06 '19 at 02:22
  • Better link https://stackoverflow.com/a/55683656/1315009 => The "next" answer to the one you are linking. – Xavi Montero May 04 '20 at 09:28