docker Web服务器退出而没有错误消息

时间:2018-10-23 01:14:04

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

我使用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来运行它,则“退出”后将显示以下行:

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的内容:

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" ]

1 个答案:

答案 0 :(得分:0)

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