5

I'm using docker-machine and docker-compose to develop a Django app with React frontend. The volumes don't get mounted on Debian environment but works properly on OSX and Windows, I've been struggling with this issue for days, I created a light version of my project that still replicate the issue you can find it in https://github.com/firetix/docker_bug. my docker-compose.yml:

django:
    build: django
    volumes:
        - ./django/:/home/docker/django/

My Dockerfile is as follow

FROM python:2.7
RUN mkdir -p /home/docker/django/
ADD . /home/docker/django/
WORKDIR /home/docker/django/
CMD ["./command.sh"]

When I run docker-compose build everything works properly. But when I run docker-compose up I get

[8] System error: exec: "./command.sh": stat ./command.sh: no such file or directory

I found this question on stackoverflow How to mount local volumes in docker machine followed the proposed workarounds with no success.

I'm I doing something wrong? Why does this work on osx and windows but not on Debian environment? Is there any workaround that works on a Debian environment? Both Osx and Debian have /Users/ folders as a shared folder when I check VirtualBox GUI.

Community
  • 1
  • 1
Rachidi Mohamed
  • 166
  • 1
  • 7

2 Answers2

1

This shouldn't work for you on OSX, yet alone Debian. Here's why:

When you add ./command.sh to the volume /home/docker/django/django/ the image builds fine, with the file in the correct directory. But when you up the container, you are mounting your local directory "on top of" the one you created in the image. So, there is no longer anything there...

I recommend adding command.sh to a different location, e.g., /opt/django/ or something, and changing your docker command to ./opt/command.sh.

Or more simply, something like this, here's the full code:

# Dockerfile
FROM python:2.7
RUN mkdir -p /home/docker/django/
WORKDIR /home/docker/django/

# docker-compose.yml
django:
    build: django
    command: ./command.sh
    volumes:
        - ./django/:/home/docker/django/
  • Not sure this is true, I just tested it on OSX el capitain Docker v 1.9.0, docker-compose 1.5.0 and it is working because Mounting on 'Top of' should override with local files command.sh, not mount an empty volume. In OSX it does override the file but on Debian I still get the error file command.sh not found. I also tried to move command.sh to a folder not being mounted /opt/ still got the same issue.@Brandon thanks for the answer! – Rachidi Mohamed Apr 21 '16 at 18:13
  • As far as I know direct host volumes must be written in absolute fashion (can use `${PWD}` env variables for that. – BlackStork Feb 15 '17 at 22:10
0

I believe this should work. there were some problems with docker-compose versions using relative paths.

 django:
   build: django
   volumes:
     - ${PWD}/django:/home/docker/django
BlackStork
  • 7,603
  • 1
  • 16
  • 18