【问题标题】:docker web server exiting without error messagedocker web 服务器退出而没有错误消息
【发布时间】:2018-10-23 01:14:03
【问题描述】:

我用 docker-compose 设置了我的项目。直到今天我重建 Web 容器时工作正常。现在,每当我想使用 docker-compose up 启动它时,它就会退出而没有错误消息:

web_1        | => Booting Unicorn
web_1        | => Rails 3.2.22.5 application starting in development on http://0.0.0.0:3000
web_1        | => Call with -d to detach
web_1        | => Ctrl-C to shutdown server
web_1        | Exiting

如果我使用 --verbose, docker-compose --verbose up 运行它,“Exiting”之后会显示以下几行:

compose.cli.verbose_proxy.proxy_callable: docker wait <- (u'a03b58f2116698d670f86155cd68605a148143b83ee3351a5e5a4808d682afc9')
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- (u'a03b58f2116698d670f86155cd68605a148143b83ee3351a5e5a4808d682afc9')
urllib3.connectionpool._make_request: http://localhost:None "POST /v1.25/containers/a03b58f2116698d670f86155cd68605a148143b83ee3351a5e5a4808d682afc9/wait HTTP/1.1" 200 30
compose.cli.verbose_proxy.proxy_callable: docker wait -> 1
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/containers/a03b58f2116698d670f86155cd68605a148143b83ee3351a5e5a4808d682afc9/json HTTP/1.1" 200 None
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {u'AppArmorProfile': u'docker-default',
 u'Args': [u'redis:6379',
           u'--',
           u'./wait-for-it.sh',
           u'postgres:5432',
           u'--',
           u'bundle',
           u'exec',
           u'rails',
           u's',

这是我的 docker-compose.yml:

version: '3'
services:
  memcached:
    image: memcached:1.5.2-alpine
    restart: always
    ports:
      - "11211:11211"

  postgres:
    image: postgres:9.4-alpine
    restart: always
    volumes:
      - ~/.myapp-data/postgres:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_DB=myapp_development
      - POSTGRES_USER=default
      - POSTGRES_PASSWORD=secret

  redis:
    image: redis:3.2.0-alpine
    restart: always
    volumes:
      - ~/.myapp-data/redis:/data
    ports:
      - "6379:6379"

  web:
    build:
      context: .
      dockerfile: "Dockerfile-dev"
    stdin_open: true
    tty: true
    command: ./wait-for-it.sh redis:6379 -- ./wait-for-it.sh postgres:5432 -- bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
      - .:/opt/apps/myapp
    depends_on:
      - memcached
      - redis
      - postgres
    ports:
      - "80:3000"
    env_file:
      - .env
    extra_hosts:
     - "api.myapp:127.0.0.1"
     - "api.getmyapp:127.0.0.1"
     - "my.app:127.0.0.1"

编辑:

这里是 Dockerfile-dev 的内容,在 cmets 上是必需的:

FROM ruby:2.3.7-slim

RUN apt-get update

RUN apt-get -y install software-properties-common libpq-dev build-essential \
    python-dev python-pip wget curl git-core \
    --fix-missing --no-install-recommends --allow-unauthenticated

# Set install path for reference later.
ENV INSTALL_PATH /opt/apps/engine
RUN mkdir -p $INSTALL_PATH
RUN gem install bundler
WORKDIR $INSTALL_PATH

ADD Gemfile $INSTALL_PATH
ADD Gemfile.lock $INSTALL_PATH
RUN bundle install

RUN find /tmp -type f -atime +10 -delete

ADD . $INSTALL_PATH
RUN cp config/database.docker-dev.yml config/database.yml

CMD [ "bundle", "exec", "rails", "s", "-p", "3000", "-b" "0.0.0.0" ]

【问题讨论】:

    标签: ruby-on-rails docker docker-compose


    【解决方案1】:

    Docker 容器在其中运行的命令完成后立即退出。从您发布的日志来看,启动服务器后容器似乎“无事可做”。您需要在前台运行该进程或拥有某种sleep 以保持容器活动。

    【讨论】:

    • 从日志看来,服务器正在前台运行。当服务器仍在运行时,容器不应退出,所以我看不出这会是什么问题。
    • 不明白@grevetii,rails 应该保持服务器运行,因此容器应该启动
    • @ntonnelier 你能发布你的Dockerfile“Dockerfile-dev”的内容吗?
    • 刚刚添加到问题@gravetii
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-16
    • 2019-07-29
    • 2016-02-17
    相关资源
    最近更新 更多