Docker - 有时我的 Web 容器无法启动,我不知道为什么

发布于 2025-01-09 15:05:51 字数 1477 浏览 1 评论 0原文

使用 Linux Mint。 我有以下 docker-compose.yml。当我运行 docker-compose up -d 时,除了我的 Web 容器之外的所有容器都会启动,这是很常见的,如果我多次运行该命令,最终我的 Web 容器就会启动。 docker 日志中没有任何内容,也没有抛出任何错误。我对为什么会发生这种事一无所知。有人可以告诉我我还能做些什么来解决这个问题吗?

使用相同的文件,在Ubuntu20.04上也会发生这种情况,但频率要低得多。

version: '3'

services:
  db:
    container_name: db_container
    image: mysql:5.6
    volumes:
      - dbBackup.sql:/docker-entrypoint-initdb.d/backup.sql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: blah
      MYSQL_DATABASE: dbname
      MYSQL_USER: myUser
      MYSQL_PASSWORD: myPassword
    ports:
      - 3306:3306
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci

  web:
    container_name: web_container
    build: ./web # This is just a centos image with a few things like httpd installed.
    volumes:
      - ./some_dir:codebase
      - ./config:codebase/config
    links:
      - redis
    depends_on:
      - db

  redis:
    container_name: redis
    image: redis

  mailhog:
    container_name: mailhog
    image: mailhog/mailhog
    ports:
      - 1025:1025
      - 8025:8025

Web 容器的 Dockerfile:

FROM centos/centos8

RUN dnf -y update && \
    dnf -y install epel-release httpd httpd-tools {more stuff}

EXPOSE 80 443

COPY docker-entrypoint.sh /usr/local/bin/

ENTRYPOINT [ "docker-entrypoint.sh" ]

docker-entrypoint.sh:

#!/bin/bash
/usr/sbin/httpd -D FOREGROUND

Using Linux Mint.
I have the following docker-compose.yml. When I run docker-compose up -d it's very common that all the containers except for my web container start up, and if I run the command several more times, eventually my web container is up. There is nothing in the docker logs and no error is thrown. I'm at my wits end as to why this happens. Can someone shed some light on what else I could do in order to figure this out?

Using the same file, this also happens on Ubuntu20.04, but it is much less frequent.

version: '3'

services:
  db:
    container_name: db_container
    image: mysql:5.6
    volumes:
      - dbBackup.sql:/docker-entrypoint-initdb.d/backup.sql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: blah
      MYSQL_DATABASE: dbname
      MYSQL_USER: myUser
      MYSQL_PASSWORD: myPassword
    ports:
      - 3306:3306
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci

  web:
    container_name: web_container
    build: ./web # This is just a centos image with a few things like httpd installed.
    volumes:
      - ./some_dir:codebase
      - ./config:codebase/config
    links:
      - redis
    depends_on:
      - db

  redis:
    container_name: redis
    image: redis

  mailhog:
    container_name: mailhog
    image: mailhog/mailhog
    ports:
      - 1025:1025
      - 8025:8025

Dockerfile for web container:

FROM centos/centos8

RUN dnf -y update && \
    dnf -y install epel-release httpd httpd-tools {more stuff}

EXPOSE 80 443

COPY docker-entrypoint.sh /usr/local/bin/

ENTRYPOINT [ "docker-entrypoint.sh" ]

docker-entrypoint.sh:

#!/bin/bash
/usr/sbin/httpd -D FOREGROUND

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文