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.
Bind mounts have been around since the early days of Docker. Bind mounts have limited functionality compared to volumes. When you use a bind mount, a file or directory on the host machine is mounted into a container. The file or directory is referenced by its absolute path on the host machine.
You can manage volumes using Docker CLI commands or the Docker API. Volumes work on both Linux and Windows containers. Volumes can be more safely shared among multiple containers. Volume drivers let you store volumes on remote hosts or cloud providers, to encrypt the contents of volumes, or to add other functionality.
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:
DOCKER_HOST=tcp://remote_host:2375 docker volume create data-volume
DOCKER_HOST=tcp://remote_host:2375 docker create -v data-volume:/data --name helper busybox true
DOCKER_HOST=tcp://remote_host:2375 docker cp /home/Bradson/data helper:/data
DOCKER_HOST=tcp://remote_host:2375 docker rm helper
DOCKER_HOST=tcp://remote_host:2375 docker run -v data-volume:/data a
This is inspired on https://stackoverflow.com/a/37469637/10042924.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With