Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 326
Bradson Avatar asked Jul 12 '18 12:07

Bradson


People also ask

Can I mount a file in docker?

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.

Can we share data volume in docker?

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.


1 Answers

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.

like image 67
Bradson Avatar answered Sep 21 '22 11:09

Bradson