容器启动延迟

时间:2019-07-29 16:01:20

标签: docker-compose

我有一个由应用程序组成的Docker撰写文件:digitalocean.com/php;网络服务器:nginx:alpine和数据库:mysql:5.7.22容器。我的问题是,当我运行“ docker-compose up –d”时,直到执行“ docker restart webserver”,我才能访问Web服务器。

我认为我必须为Web服务器添加一个延迟启动,这是我使用等待脚本尝试的:

  #Nginx Service
  webserver:
    image: nginx:alpine
    container_name: webserver
    restart: unless-stopped
    tty: true
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./:/var/www
      - ./nginx/conf.d/:/etc/nginx/conf.d/
      - ./wait-for-it.sh:/wait-for-it.sh
    depends_on:
      - app
      - db
    entrypoint: ./wait-for-it.sh db:3306
    networks:
      - app-network

但是,问题仍然存在。入口点呼叫是否错误,或者我如何才能延迟启动?

谢谢 斯蒂芬

1 个答案:

答案 0 :(得分:0)

我不确定我是如何解决它的,但似乎可行。在我的网络服务器上,我有额外的条件:

depends_on:
      - app

在该应用中,我添加了以下运行状况检查:

  app:
    build:
      context: .
      dockerfile: Dockerfile
    image: digitalocean.com/php
    healthcheck:
            test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
            timeout: 20s
            retries: 10

我不确定它的作用,但至少现在不必重启Web服务器