Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Host Volumes Not getting mounted on 'Docker-compose up'

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.

like image 354
Rachidi Mohamed Avatar asked Nov 08 '22 16:11

Rachidi Mohamed


1 Answers

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/
like image 144
Brandon Stiles Avatar answered Nov 15 '22 06:11

Brandon Stiles