How to mount directories from a docker-machine to my local host?

0 votes
How can i mount a directory from a docker-machine to my local host machine?
Jul 9 in Docker by Ruby
14 views

1 answer to this question.

0 votes

You could do this using the docker-machine mount command.

Using this command,you can mount directories from a machine to your local host, using sshfs.

The notation is machinename:/path/to/dir for the argument; you can also supply an alternative mount point (default is the same dir path).

consider an example:

$ mkdir foo
$ docker-machine ssh dev mkdir foo
$ docker-machine mount dev:/home/docker/foo foo
$ touch foo/bar
$ docker-machine ssh dev ls foo
bar

Now you can use the directory on the machine, for mounting into containers. Any changes done in the local directory, is reflected in the machine too.

$ eval $(docker-machine env dev)
$ docker run -v /home/docker/foo:/tmp/foo busybox ls /tmp/foo
bar
$ touch foo/baz
$ docker run -v /home/docker/foo:/tmp/foo busybox ls /tmp/foo
bar
baz

The files are actually being transferred using sftp (over an ssh connection).

answered Jul 9 by Sirajul
• 5,960 points

Related Questions In Docker

+4 votes
4 answers

How To Access a Service on Host From a Docker Container?

Adding to kalgi's answer, You can also ...READ MORE

answered Oct 16, 2018 in Docker by lina
• 8,100 points

edited Oct 16, 2018 by lina 3,225 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How do I copy a file from docker container to host?

Here is a way which you can ...READ MORE

answered Aug 27, 2018 in Docker by Damon Salvatore
• 5,490 points
1,455 views
0 votes
1 answer
0 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 56,160 points
99 views
0 votes
1 answer

How to move Docker containers from one host to another?

Yes you could definitely do it the ...READ MORE

answered Jul 2 in Docker by Sirajul
• 5,960 points
16 views
0 votes
1 answer

How to connect shell to my new docker host?

Use the following command to connect your ...READ MORE

answered Jul 4 in Docker by Sirajul
• 5,960 points
13 views