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
126 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
• 39,540 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,110 points

edited Oct 16, 2018 by lina 5,414 views
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,510 points
3,922 views
0 votes
1 answer

How to run a docker command from inside the container?

You must have come across the /var/run/docker.sock file, ...READ MORE

answered Jun 28, 2018 in Docker by Sophie may
• 9,870 points
414 views
0 votes
1 answer

How to obtain the Docker container's IP address from the host?

This can be done by executing the ...READ MORE

answered Jul 16, 2018 in Docker by Sophie may
• 9,870 points
985 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,940 points
232 views
0 votes
2 answers