【发布时间】:2018-09-19 14:24:33
【问题描述】:
我尝试使用 Ruby on Rails 应用程序构建 Docker 容器,但无法做到。
Dockerfile
FROM ruby:2.5.1
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /noteapp
WORKDIR /noteapp
ADD Gemfile /noteapp/Gemfile
ADD Gemfile.lock /noteapp/Gemfile.lock
RUN bundle install
ADD . /noteapp
CMD ["rails","server","-b","0.0.0.0"]
docker-compose.yml
version: '2'
services:
db:
image: postgres
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/noteapp
ports:
- "3000:3000"
depends_on:
- db
运行命令后
sudo docker-compose up --build
我得到了结果,noteapp_web_1 exited with code 0 执行此操作后,我尝试启动 docker 容器,一切正常,但我的应用程序在 localhost:3000 上没有响应
当我尝试查看日志时(sudo docker logs id),我得到了结果 console_result
但是当我尝试连接到我的容器时,我不能这样做,并且出现错误:
sudo docker attach ee43805fd6cf
You cannot attach to a stopped container, start it first
我应该怎么做才能运行我的应用程序?
更新,我使用了@Upendra Chahar 的解决方案 并遇到了这个问题 rails_error
之后我解决了这个问题,现在我遇到了 postgresql db 的问题: postgresql_db
【问题讨论】:
标签: ruby-on-rails docker docker-compose dockerfile