Compose: Unable to find GemFile

Created on 28 Sep 2015  路  19Comments  路  Source: docker/compose

Hey all,

I'm currently configuring docker-compose on my Linux Mint machine. The problem is, I'm able to build the web aspect of my project without errors. However, when it comes to running the rails server, rails console, or really anything that involves the rails command, I'm getting the following errors:

web_1 | Could not locate Gemfile or .bundle/ directory

/myapp/Gemfile not found

Any idea what's going on here. Posting my docker-compose.yml and related files below.

Docker Version: 1.8.2
Docker Machine Version: 0.4.0
Docker Compose Version: 1.4.2

docker-compose.yml

db:
  image: postgres:9.4.1
  ports:
    - "5432:5432"

web:
  extends:
    file: common.yml
    service: webapp
  build: .
  command: bundle exec thin -D start
  ports:
      - "3000:3000"
  links:
      - db

Common.yml

webapp:
  environment:
      RAIL_ENV: development
  volumes:
      - .:/myapp

Dockerfile

FROM ruby:2.2.2

ENV LANG C.UTF-8

RUN apt-get update -qy
RUN apt-get upgrade -y
RUN apt-get update -qy
RUN apt-get install -y build-essential

# for postgres
RUN apt-get install -y libpq-dev

# for nokogiri
RUN apt-get install -y libxml2-dev libxslt1-dev

# for capybara-webkit
#RUN apt-get install -y libqt4-webkit libqt4-dev xvfb

# for a JS runtime
RUN apt-get install -y nodejs

ENV APP_HOME /myapp
RUN mkdir $APP_HOME
WORKDIR $APP_HOME

ADD Gemfile* $APP_HOME/
RUN bundle install

ADD . $APP_HOME
kinquestion

Most helpful comment

The volume is masking the contents of the image. You need to either remove volumes: - .:/srv/app or make sure that you have the bundle contents on the host as well. The Compose guides do this by running something like docker-compose run app bundler install ...

All 19 comments

I think it has to do with volumes: - .:/myap. If you use a volume you mask everything you added to the container at that path.

Any idea how to unmask it?

Turns out, it require changing the volume to the following:

webapp:
  environment:
      RAIL_ENV: development
  volumes:
      -  $PWD:/app

So, it turns out that mounting the volume in that manner didn't really work too well. It just served the bundled app. Any changes I make to the app while the server is running do _not_ take place until I rebuild the app.

Obviously, when you're doing a lot of work to an app, this is extremely frustrating. However, its only really happening on the Linux environments I've worked in. OSX seems to be fine.

Any idea as to why this is happening?

I would recommend trying the following:

  1. Upgrade to the latest docker-compose 1.5.0
  2. run a docker-compose rm to clear out old volumes, then do up again.

.:/myapp should work as a volume path

Hi,

I will keep looking, but this issue seems to be happening under the latest docker-compose and company.

laptop:testing ronaldpetty$ docker-compose rm
No stopped containers
laptop:testing ronaldpetty$ docker-compose run web rails new . --force --database=postgresql --skip-bundle
/myapp/Gemfile not found
laptop:testing ronaldpetty$ docker-compose -v
docker-compose version 1.5.2, build 7240ff3

Same issue, how to debug this?
This is amazingly frustrating and still not resolved it!

I was ran in the same problem, so, in my Dockerfile I put COPY Gemfile Gemfile right after WORKDIR $INSTALL_PATH and right before CMD bundle install:

...
WORKDIR $INSTALL_PATH
COPY Gemfile Gemfile
RUN bundle install
...

And it solves my problem.

tried that..

Could not locate Gemfile or .bundle/ directory

Still the same

My docker file is like this:


FROM ruby:2.3.0

EXPOSE  80
EXPOSE  22
ENV     RAILS_ENV   production
ENV     TERM        xterm

RUN \
        apt-get -y update \
        && apt-get install -y --force-yes software-properties-common \nginx lynx nano curl build-essential autoconf automake libass-dev libfreetype6-dev \
        && apt-get clean \
        && rm -rf /var/lib/apt/lists/*

# --------------------------------------
# BUNDLER
# --------------------------------------
WORKDIR /tmp
ADD     .               /tmp
ADD     .               /srv/app
ADD     ./Gemfile       /srv/app/Gemfile
ADD     ./Gemfile.lock  /srv/app/Gemfile.lock
#RUN     gem install rubygems-update --no-ri --no-rdoc
RUN     gem install bundle --no-ri --no-rdoc
WORKDIR /srv/app
COPY    Gemfile Gemfile
RUN     bundler install --jobs 7 --without development test
#RUN    bundle exec rake assets:precompile --trace


Please include your docker-compose.yml, the command you ran, and the output it produced.

My docker-compose.yml

app:
  build: .
  command: bundle exec rails s -p 3000 -b '0.0.0.0'
  volumes:
    - .:/srv/app
  ports:
    - "3000:3000"
    - "80:80"
  links:
    - db
  env_file:
    - '.env.app'
db:
  image: postgres
  ports:
    - "5432:5432"

docker-compose goes OK

BUT

docker-compose up throws:

db_1  | LOG:  database system was interrupted; last known up at 2016-01-18 22:21:18 UTC
db_1  | LOG:  database system was not properly shut down; automatic recovery in progress
db_1  | LOG:  invalid record length at 0/1707A08
db_1  | LOG:  redo is not required
db_1  | LOG:  MultiXact member wraparound protections are now enabled
db_1  | LOG:  database system is ready to accept connections
db_1  | LOG:  autovacuum launcher started
app_1 | Could not locate Gemfile or .bundle/ directory
app_app_1 exited with code 10

The volume is masking the contents of the image. You need to either remove volumes: - .:/srv/app or make sure that you have the bundle contents on the host as well. The Compose guides do this by running something like docker-compose run app bundler install ...

dnephin:
Thank you for your reply; was this recently changed?
How would I keep the volume mount in docker-compose without issues?
Im running Docker on OSX so I assume this is probably the issue with the volume mount somehow not working correctly therefore the bundle folder and Gemfile cannot be found

No it was not recently changed, it's been this way forever. It doesn't have anything to do with osx.

If you want to keep the volume, you need to generate the bundle directory using docker-compose run ... as I suggested.

Thank you this totally fixed my issue.

I'm too getting this issue in ubuntu 14.04.
@dnephin if i remove volumes from compose file, then do i need to run bundle install again, isn't there another way to resolve this behaviour. Same configurations was working fine for few days but, now I'm facing the issue mentioned, probably due to virutalbox instance is my guess right ?

I'm leaving this comment as a signpost for others. The error message in the OP matched one I encountered while using a volume for bundled gems between containers ( api, resque, resque-scheduler etc).

I hit the same error using Fedora25 with SELinux and Win10 using docker-toolbox.
For SELinux Permissive works, bundle completes in the build phase.
For win10 it was due to the project being outside the Users folder. Moving it inside Users home allowed progress.

HTH

(Almost) same her as Colindensem, but on Win7 instead of Win10. Whole project copied to Users folder, and starting from there: problem solved.
This is not an option on the long term, but for the time being i at least can run my project.
(Using this as a clue, we might find a solution that will keep the app's on the development drive)

I had pretty much the same error, I also posted here. For docker-machine to work on Windows, we must place project files somewhere inside C:/Users/ otherwise volumes won't mount, leaving an empty folder.

I suppose one can add a shared folder on the docker-machine in virtualbox's settings in case project is in a different drive, but I did not go this way. We simply moved the project to a valid place.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leiblix picture leiblix  路  3Comments

bergtwvd picture bergtwvd  路  3Comments

saulshanabrook picture saulshanabrook  路  3Comments

davidbarratt picture davidbarratt  路  3Comments

Hendrik-H picture Hendrik-H  路  3Comments