Search code examples
ruby-on-railsdockerdocker-composevolumes

docker-compose empty volume with a rails app on OSX


Not sure how to ask this question because I can't understand the problem. Also, I'm not a docker expert and this may be a stupid issue.

I have a Rails project with docker-compose. And there's 2 situations. First I'm able to build and run the app with docker-compose up and everything looks fine, the problem is the code is not reloading when I change it. Second, when I add a volume in docker-compose.yml, docker-compose up exit because Gemfile can't be found, the mounted folder is empty.

Dockerfile and docker-compose.yml extract, I renamed some stuff:

# File: Dockerfile.app
FROM ruby:2.5-slim-stretch

RUN apt-get update -qq && apt-get install -y redis-tools
RUN apt-get install -y autoconf bison build-essential  #(..etc...)

RUN echo "gem: --no-document" > ~/.gemrc
RUN gem install bundler

ADD . /docker-projects
WORKDIR /docker-projects/project1/core
ENV BUNDLE_APP_CONFIG /docker-projects/project1/core/.bundle
RUN /bin/sh -c bundle install --local --jobs

# File: docker-compose.yml
app:
  build: .
  dockerfile: Dockerfile.app
  command: /bin/sh -c "bundle exec rails s -p 8080 -b 0.0.0.0"
  ports:
    - "8080:8080"
  expose:
    - "8080"
  volumes:
    - .:/docker-projects
  links:
    - redis
    - mysql
    - memcached

My 'docker-projects' is a big project made of different rails_engines and gems libraries. We manage this with the 'repo' tool.

Running docker-compose build app work fine, and I can see bundle install logs. Then docker-compose up app exit with error 'Gemfile not found'.

It was working with no problem till I decided to recover 50gb of space from docker containers and rebuild everything. Not sure what changed.

If I add the volume(docker-compose), the mounted volume is empty. If I remove the volume(docker-compose), the code is not reloading as it was.

Versions I'm using:

Docker version 18.09.7, build 2d0083d
OSX 10.14.5
docker (through brew) with xhyve driver

I tried with a new basic docker-compose project and I didn't have this issue. Any ideas? I'll keep looking.

Thanks.


Solution

  • Ok, I found the problem. This is the command I was using to generate my docker-machine:

    docker-machine create default \
    --driver xhyve \
    --xhyve-cpu-count 4 \
    --xhyve-memory-size 12288 \
    --xhyve-disk-size 256000 \
    --xhyve-experimental-nfs-share \
    --xhyve-boot2docker-url https://github.com/boot2docker/boot2docker/releases/download/v18.06.1-ce/boot2docker.iso 
    

    I probably did an upgrade in the middle because didn't work anymore. The docker-maching showed some warnings about NFS conflicts with my existing /etc/exports definition but the machine was created.

    After searching around, I realize I have to rewrite the command above like this:

    docker-machine create default \
    --driver=xhyve \
    --xhyve-cpu-count=4 \
    --xhyve-memory-size=12288 \
    --xhyve-disk-size=256000 \
    --xhyve-boot2docker-url="https://github.com/boot2docker/boot2docker/releases/download/v18.06.1-ce/boot2docker.iso" \
    --xhyve-experimental-nfs-share=/Users \
    --xhyve-experimental-nfs-share-root "/"
    

    The difference beside the '=' is the *-nfs-share options. I commented my /etc/exports to avoid the conflict warning, and recreated the machine. Now it works like it was before.

    The option --xhyve-experimental-nfs-share-root is "/xhyve-nfsshares" by default, so I changed to "/" where I have it.