简体   繁体   中英

Docker compose up fails with `require': cannot load such file — rack/handler/rails (LoadError)

This is my Dockerfile:

FROM rails:4.2.4
MAINTAINER Brena Monteiro <me@monteirobrena.com>
RUN mkdir -p ~/myapp
COPY . ~/myapp
COPY Gemfile ~/myapp/Gemfile
COPY Gemfile ~/myapp/Gemfile.lock
WORKDIR ~/myapp
RUN bundle install
CMD rails s -b 0.0.0.0

And my docker-compose.yml :

web:
  build: .
  command: rails s -p 3000 -b '0.0.0.0'
  ports:
    - '3000:8080'
  volumes:
    - .:/Users/monteirobrena/myapp

If I run docker run the Docker is start correctly:

docker run -v ./:/Users/monteirobrena/docker/myapp -p 3000:8080 myapp

But when I run docker-compose up I receive this error:

➜  app git:(add-docker) ✗ docker-compose up         
myRecreating app_web_1
myAttaching to app_web_1
web_1 | /usr/local/bundle/gems/rack-1.6.4/lib/rack/handler.rb:78:in `require': cannot load such file -- rack/handler/rails (LoadError)
web_1 |   from /usr/local/bundle/gems/rack-1.6.4/lib/rack/handler.rb:78:in `try_require'
web_1 |   from /usr/local/bundle/gems/rack-1.6.4/lib/rack/handler.rb:16:in `get'
web_1 |   from /usr/local/bundle/gems/rack-1.6.4/lib/rack/server.rb:290:in `server'
web_1 |   from /usr/local/bundle/gems/railties-4.2.3/lib/rails/commands/server.rb:125:in `print_boot_information'
web_1 |   from /usr/local/bundle/gems/railties-4.2.3/lib/rails/commands/server.rb:75:in `start'
web_1 |   from /usr/local/bundle/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:80:in `block in server'
web_1 |   from /usr/local/bundle/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:75:in `tap'
web_1 |   from /usr/local/bundle/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:75:in `server'
web_1 |   from /usr/local/bundle/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
web_1 |   from /usr/local/bundle/gems/railties-4.2.3/lib/rails/commands.rb:17:in `<top (required)>'
web_1 |   from /usr/src/app/bin/rails:9:in `require'
web_1 |   from /usr/src/app/bin/rails:9:in `<top (required)>'
web_1 |   from /usr/local/bundle/gems/spring-1.6.4/lib/spring/client/rails.rb:28:in `load'
web_1 |   from /usr/local/bundle/gems/spring-1.6.4/lib/spring/client/rails.rb:28:in `call'
web_1 |   from /usr/local/bundle/gems/spring-1.6.4/lib/spring/client/command.rb:7:in `call'
web_1 |   from /usr/local/bundle/gems/spring-1.6.4/lib/spring/client.rb:28:in `run'
web_1 |   from /usr/local/bundle/gems/spring-1.6.4/bin/spring:49:in `<top (required)>'
web_1 |   from /usr/local/bundle/gems/spring-1.6.4/lib/spring/binstub.rb:11:in `load'
web_1 |   from /usr/local/bundle/gems/spring-1.6.4/lib/spring/binstub.rb:11:in `<top (required)>'
web_1 |   from /usr/src/app/bin/spring:13:in `require'
web_1 |   from /usr/src/app/bin/spring:13:in `<top (required)>'
web_1 |   from bin/rails:3:in `load'
web_1 |   from bin/rails:3:in `<main>'
web_1 | Exiting
myapp_web_1 exited with code

Any ideas?

Use bundle exec to start the rails server, like this:

 web:
  build: .
  command: bundle exec rails s -p 3000 -b '0.0.0.0'
  ports:
    - '3000:8080'
  volumes:
    - .:/Users/monteirobrena/myapp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM