user128511
user128511

Reputation:

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)

Upvotes: 3

Views: 356

Answers (2)

Festus Fashola
Festus Fashola

Reputation: 161

All you have to do is, before launching docker-machine:

export VIRTUALBOX_SHARE_FOLDER="$PWD:$PWD"

Upvotes: 0

dnephin
dnephin

Reputation: 28150

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.

Upvotes: 1

Related Questions