12

I'm pretty comfortable using Docker recently, typically to test websites to make sure they run properly on servers before I deploy them.

Typically, I mount my local directory to the locally running image like:

docker run -v c:\temp\website:/var/www/html (you get the picture)

What I am curious about is if there is a way to mount my local volume to a remote server running docker. I'm pretty sure the answer is no, unless I poke wholes in firewalls and such to make a local volume share externally.

But, I thought I would ask. Docker seems to be doing some amazing things quickly.

Nakilon
  • 34,866
  • 14
  • 107
  • 142
user3888307
  • 2,825
  • 5
  • 22
  • 32
  • From what I have read docker volumes must exist on the host, they cannot be from a remote source. I've been looking to do the opposite of you want to do. A local container with a remote volume. – Benjamin Slabbert Sep 28 '17 at 08:31
  • I did a look up for volume drivers and found this: See: [flocker](https://github.com/ScatterHQ/flocker). Which won't help your situation, but provides a way to use remote volumes – Benjamin Slabbert Sep 28 '17 at 08:37
  • @BenjaminSlabbert , Hi I am trying to do almost the same as you. My production remote docker container is running on Elastibeanstalk on AWS and I want to take a snapshot/copy of its volume and connect my local docker container to it(the purpose is to populate the local env with prod-alike data and testing), can you please reply here with anything you think its useful for this case!?thanks – Yusuf Jun 18 '22 at 21:30
  • 1
    Hi @Yusuf, what I would suggest is to create EBS snapshots, see: [EBSSnapshots](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSSnapshots.html) this will then create regular backups of your docker volume which you can then use at a later point for testing. I would also recommend that the EBS volume you use for the docker volume and these backups is not the root volume. How to use the remove volume for a local docker container I do not know, but perhaps it is acceptable in your case to download the data to your machine. – Benjamin Slabbert Jun 25 '22 at 18:32

1 Answers1

10
  1. First share your local directory in Windows. Lets assume your shared folder is \\windowsip\website.
  2. Then login into the remote linux machine where docker engine is running, and be sure you can mount a windows shared folder: sudo apt install cifs-utils
  3. Try to connect to your share: sudo mount -t cifs -o user=******,password=******,uid=ubuntu,gid=ubuntu //windowsip/website /home/ubuntu/website
  4. When everything is working lets do the same with docker. Create a named volume as follows: docker volume create --driver local --opt type=cifs --opt device='//windowsip/website' --opt o='username=*****,password=*****' website
  5. docker run -v website:/var/www/html

I know it is an old thread but just I had the same problem, hope it helps to others

Okey Okey I didn't read the last part of the question. Yes, you need to poke holes in the firewall. But still is useful, I have a linux server with docker and I use it via VPN when I work from home in my laptop. The container has local access to everything.

Nakilon
  • 34,866
  • 14
  • 107
  • 142
Carlos Rafael Ramirez
  • 5,984
  • 1
  • 29
  • 36