码头工人没有开始退出红宝石

时间:2017-07-12 20:07:52

标签: docker

我正在尝试构建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/

1 个答案:

答案 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'"]

并继续使用上面的buildrun命令:

docker build -t test .
docker run -d -p 3000:3000 --name railsserver test

您遇到的问题是运行服务器的bundle exec rails s命令,在构建期间由RUN执行。它应该推迟到使用CMD

的容器执行