Docker - 有时我的 Web 容器无法启动,我不知道为什么
使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论