简体   繁体   中英

mounting docker-machine VM folders in container with docker-compose

I have a docker-container.yml with

mycontainer:
  image: someimage
  volumes:
   - ./backup:/backup

On a real linux docker installation that will make the host docker machine's ./backup appear at /backup in the container

with docker-compose and docker-machine though there's 3 machines

  1. the host
  2. the VM running linux with docker
  3. the container

The problem I'm running into is I'm trying to write some scripts from the POV of the machine running docker. But because docker-compose + docker-machine doesn't mount the VMs ./backup into the container my scripts don't work.

Is there a way to get ./backup to appear in the VM. Either

(a) it's in all 3 machines in some way or (b) it's only in the VM and container so that way it matches production.

If it's not clear (am sure this will make it less clear) there's always 3 machines

In Dev

[my laptop] -> [vm running docker] -> [container]

In Production

[my laptop] -> [remote machine running docker] -> [container]

I'm trying to write some maintenance scripts that run on my laptop. They ssh to the docker machine (local VM or remote) and do some stuff. But they need things to appear the same (I thought that was the point of docker. It's always supposed to be the same). But in this case it's not

In Dev running docker-compose up -d I get

[my laptop] -> [thing running docker] -> [container] 
    |                                        |
(./backup) ------------------------------>(/backup)

In Production also running docker-compose up -d I get

[my laptop] -> [thing running docker] -> [container] 
                     |                       |
                 (./backup) ------------->(/backup)

I need Dev to either be this

[my laptop] -> [thing running docker] -> [container] 
                     |                       |
                 (./backup) ------------->(/backup)

Or this

[my laptop] -> [thing running docker] -> [container] 
    |                |                       |
(./backup) ------>(./backup) ------------>(/backup)

If you're using docker-machine with virtualebox it should mount your home directory as a shared folder in the VM. If ./backup is not in your home directory you'll need to add another shared folder so that the machine can see it properly.

你所要做的就是,在启动 docker-machine 之前:

export VIRTUALBOX_SHARE_FOLDER="$PWD:$PWD"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM