Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find rake-11.1.2 in rails docker container

I'm running two docker containers. One with rails and one with Postgres db. Here is my docker-compose file:

# Docs: https://docs.docker.com/compose/compose-file/
version: '2'
services:
  db:
    image: postgres
    environment: 
      - POSTGRES_PASSWORD=xxx

  rails:
    build: .
    command: rails s -p 3000 -b '0.0.0.0'
    volumes:
      - .:/app
    ports:
      - "3000:3000"
    links:
      - db
    depends_on:
      - db

Here the Dockerfile for the rails app:

FROM ruby:2.3

RUN apt-get update 
RUN apt-get install -y build-essential nodejs 

RUN mkdir -p /app
WORKDIR /app

COPY Gemfile Gemfile.lock ./ 
RUN gem install bundler && bundle install --jobs 20 --retry 5

COPY . ./

EXPOSE 3000

ENTRYPOINT ["bundle", "exec"]

CMD ["rails", "server", "-b", "0.0.0.0"]

When I run docker-compose up everything works fine and I can connect to the server via the ip address from docker-machine.

When I try to connect to the container with the following command:

docker-compose run rails console

I get this error:

Could not find rake-11.1.2 in any of the sources
Run `bundle install` to install missing gems.

bundle install inside the container has no effect and the mentioned gem is definitely installed. In other stack-overflow questions were mentioned that I should run bin/spring stop. So I ran:

docker-compose run bin/spring stop

And it returns:

Spring is not running

I'm still comparibly new to ruby/rails and docker. I hope someone can help me here! Thanks in advance

PS: Comments on the Dockerfiles are appreciated!

like image 488
dennis-tra Avatar asked May 15 '16 11:05

dennis-tra


1 Answers

seems to be a late response but I will answer anyway. My educated guess is that your Gemfile.lock is pinning your rake version and that is why it is complaining. If you run the docker build without a volume defined like in your docker-compose.yml you can easily end up like this. So give it a try.

In regard to your Dockerfile: If you use this only for development purposes then this might be ok. Otherwise you should think about running it using a different user (create user with useradd and run RUN tasks and so on accordingly). You might also want to use some bundler features like the --path=<path> option.

like image 149
kgalli Avatar answered Oct 24 '22 13:10

kgalli