我正在运行两个码头集装箱.一个带有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 app的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时,一切正常,我可以通过docker-machine的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.
容器内的bundle install没有效果,所提到的gem肯定是安装好的.在其他堆栈溢出问题中提到我应该运行bin / spring stop.所以我跑了:
docker-compose run bin/spring stop
它返回:
Spring is not running
我仍然是ruby / rails和docker的新手.我希望有人可以帮助我!
提前致谢
PS:对Dockerfiles的评论表示赞赏!
最佳答案
原文链接:https://www.f2er.com/docker/436641.html