在rails docker容器中找不到rake-11.1.2
我正在运行两个docker集装箱。 一个与铁轨和一个Postgres分贝。 这是我的docker-compose文件:
# 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
这里的rails应用程序的Dockerfile:
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"]
当我运行docker-compose up
一切正常,我可以通过docker机器的IP地址连接到服务器。
当我尝试使用以下命令连接到容器时:
docker-compose run rails console
我得到这个错误:
Could not find rake-11.1.2 in any of the sources Run `bundle install` to install missing gems.
捆绑安装在容器内没有任何作用,并提到的gem是绝对安装。 在其他堆栈溢出问题中提到我应该运行bin/spring stop
。 所以我跑了:
docker-compose run bin/spring stop
然后它返回:
Spring is not running
我还是比较新的ruby/铁轨和docker。 我希望有人能帮助我! 提前致谢
PS:对Dockerfiles的评论非常感谢!
似乎是一个迟到的反应,但我会回答。 我的教育猜测是你的Gemfile.lock
钉住你的rake
版本,这就是为什么抱怨。 如果你运行的docker build
没有在你docker-compose.yml
定义的卷, docker-compose.yml
你可以很容易地结束。 所以试试吧。
关于你的Dockerfile
:如果你只用于开发目的,那么这可能是好的。 否则,您应该考虑使用不同的用户来运行它(使用useradd
创build用户并相应地运行RUN
任务等)。 您可能还想使用一些捆绑程序function,如--path=<path>
选项。