我正在尝试构建Docker容器并启动服务器。当我们成功使用docker build -t . test
创建容器时。当我们以docker run -d -p 3000:3000 --name railsserver test
启动容器时,其启动退出状态为0,但无法看到任何进程或任何打开的端口3000
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
da70e26109b3 foodex "irb" 40 seconds ago Exited (0) 22 seconds ago admiring_heyrovsky
73d4a7ca58d0 foodex "irb" About a minute ago Created jolly_ramanujan
4594ad5ea4ce foodex "irb" 6 minutes ago Exited (0) 6 minutes ago tender_murdock
Dockerfile
FROM ruby
RUN apt-get update -qq && apt-get install -y \
build-essential libpq-dev nodejs mysql-client libmysqlclient-dev ssh
RUN mkdir -p /foodex/
WORKDIR /foodex/
ADD Gemfile Gemfile.lock /
RUN bundle install
#RUN source ~/.bashrc
EXPOSE 3000
RUN bundle exec rails s -p 3000 -b '0.0.0.0'
ADD . /foodex/
答案 0 :(得分:0)
将您的Dockerfile更新为:
FROM ruby
RUN apt-get update -qq && apt-get install -y \
build-essential libpq-dev nodejs mysql-client libmysqlclient-dev ssh
COPY ./ /foodex/
WORKDIR /foodex/
RUN bundle install
EXPOSE 3000
CMD ["bundle", "exec", "rails", "s", "-p", "3000", "-b", "'0.0.0.0'"]
并继续使用上面的build
和run
命令:
docker build -t test .
docker run -d -p 3000:3000 --name railsserver test
您遇到的问题是运行服务器的bundle exec rails s
命令,在构建期间由RUN
执行。它应该推迟到使用CMD