我在运行两个码头容器。一个使用rails,另一个使用Postgres db。这是我的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
时,一切运行正常,我可以通过ip地址从docker-machine连接到服务器。
当我尝试使用以下命令连接到容器时:
docker-compose run rails console
我得到了这个错误:
Could not find rake-11.1.2 in any of the sources
Run `bundle install` to install missing gems.
在容器内安装bundle没有任何效果,并且肯定安装了前面提到的gem。在其他堆栈溢出问题中,有人提到我应该运行bin/spring stop
。所以我跑了:
docker-compose run bin/spring stop
然后返回:
Spring is not running
我对ruby/rails和docker还是比较陌生的。我希望有人能在这里帮助我!提前感谢
附言:感谢对Dockerfiles的评论!
发布于 2016-07-21 14:06:27
这似乎来得太晚了,但我还是会回答的。我有根据的猜测是,你的Gemfile.lock
正在固定你的rake
版本,这就是为什么它会抱怨。如果您没有像在docker-compose.yml
中那样定义卷来运行docker build
,那么您很容易就会像这样结束。所以试一试吧。
关于您的Dockerfile
:如果您仅将其用于开发目的,那么这可能是可以的。否则,您应该考虑使用其他用户来运行它(使用useradd
创建用户并相应地运行RUN
任务,依此类推)。您可能还想使用一些捆绑器特性,比如--path=<path>
选项。
发布于 2018-03-06 21:19:33
我们也有同样的问题。尽管Spring说它没有运行,但我的同事向我指出,如果我查看bin/rails
,我会发现它实际上将与Rails一起运行。在Gemfile
中删除与spring
相关的gem解决了这个问题。
发布于 2020-09-21 09:10:14
我通过在我的Dockerfile
中使用这个命令设法解决了这个问题。
RUN bundle install --without development test --with runtime --deployment
https://stackoverflow.com/questions/37237943
复制相似问题