4x99 / code6

码小六 - GitHub 代码泄露监控系统
GNU General Public License v3.0
1.13k stars 201 forks source link

启动容器报错-container for service "mysql" is unhealthy #218

Closed lianghdx closed 2 years ago

lianghdx commented 2 years ago

安装方式

Docker-Compose 安装

问题描述

liang@liang:~/code6$ docker-compose --env-file .env.docker-compose up -d --build [+] Running 8/8 ⠿ mysql Pulled 68.9s ⠿ cdd8b07c6082 Pull complete 37.9s ⠿ c2f1720beca1 Pull complete 38.0s ⠿ 39f143a8d6de Pull complete 64.4s ⠿ 118a8285b641 Pull complete 64.4s ⠿ b45cbcaf75c7 Pull complete 64.5s ⠿ d4574372e600 Pull complete 64.5s ⠿ 1f565a3cbc52 Pull complete 64.6s [+] Building 116.8s (10/10) FINISHED
=> [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 1.75kB 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/php:7.4-apache 2.8s => [internal] load build context 0.1s => => transferring context: 10.73MB 0.1s => [1/5] FROM docker.io/library/php:7.4-apache@sha256:521e31396b02e61d0 72.7s => => resolve docker.io/library/php:7.4-apache@sha256:521e31396b02e61d0f 0.0s => => sha256:30857d53af4d785712b5078606ad2f67e09c06d6a 12.51kB / 12.51kB 0.0s => => sha256:521e31396b02e61d0f1b70c85aeef7e20bd71d55c9b 1.86kB / 1.86kB 0.0s => => sha256:7a6db449b51b92eac5c81cdbd82917785343f166 31.38MB / 31.38MB 44.4s => => sha256:ad2afdb99a9d0074f3f4cf106eadc79b4725512152f787f 226B / 226B 1.0s => => sha256:dbc5aa907229dc1b68c41503097b4284fb91e9db 91.60MB / 91.60MB 69.3s => => sha256:f2e8c86002a794426a68537dc772c680865065da412 3.04kB / 3.04kB 0.0s => => sha256:82f252ab4ad1fdf41f596e30581e6426b41344e2de0690a 270B / 270B 1.6s => => sha256:bf5b34fc989492bb01a5ef99d15326a5591bd73c 19.24MB / 19.24MB 21.6s => => sha256:6161651d3d9547dfaa5341136fb8bb47fe72be12fc9351 475B / 475B 21.9s => => sha256:cf2adf296ef11e87460e2f68e275cedc5697aad22c9531 513B / 513B 22.2s => => sha256:d921da48d5549130879337ec495472fbe154dca3 10.76MB / 10.76MB 31.5s => => sha256:b18a4562cdb2e175e5665c5bbfd58ae575838363b13125 493B / 493B 32.3s => => sha256:c2620408b8f15c8016e2df26732b0da805d64e25 10.20MB / 10.20MB 42.9s => => sha256:7674ea7f8b6487131c7cad6fb80bb5226489743002 2.46kB / 2.46kB 43.9s => => sha256:d424de41e878e637fa8eb21a53bfe9e3bbd629b31ba330 245B / 245B 44.3s => => sha256:95dce5dc9f57d624ed13932549b2cab73091fa19740d5a 895B / 895B 44.5s => => extracting sha256:7a6db449b51b92eac5c81cdbd82917785343f1664b2be57b 0.8s => => extracting sha256:ad2afdb99a9d0074f3f4cf106eadc79b4725512152f787fa 0.0s => => extracting sha256:dbc5aa907229dc1b68c41503097b4284fb91e9db3974c9a3 1.8s => => extracting sha256:82f252ab4ad1fdf41f596e30581e6426b41344e2de0690a7 0.0s => => extracting sha256:bf5b34fc989492bb01a5ef99d15326a5591bd73cb28ed46f 0.3s => => extracting sha256:6161651d3d9547dfaa5341136fb8bb47fe72be12fc935111 0.0s => => extracting sha256:cf2adf296ef11e87460e2f68e275cedc5697aad22c9531c0 0.0s => => extracting sha256:d921da48d5549130879337ec495472fbe154dca3238c5538 0.1s => => extracting sha256:b18a4562cdb2e175e5665c5bbfd58ae575838363b13125c6 0.0s => => extracting sha256:c2620408b8f15c8016e2df26732b0da805d64e25acc69260 0.3s => => extracting sha256:7674ea7f8b6487131c7cad6fb80bb5226489743002a69005 0.0s => => extracting sha256:d424de41e878e637fa8eb21a53bfe9e3bbd629b31ba3305b 0.0s => => extracting sha256:95dce5dc9f57d624ed13932549b2cab73091fa19740d5a56 0.0s => [2/5] COPY . /var/www/html 0.6s => [3/5] COPY docker-entrypoint.sh docker-entrypoint.sh 0.0s => [4/5] WORKDIR /var/www/html 0.0s => [5/5] RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak;echo 'd 39.7s => exporting to image 0.9s => => exporting layers 0.9s => => writing image sha256:0f28be3927e171d19fed4250478948832cedb8f1d39be 0.0s => => naming to docker.io/library/code6 0.0s

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them [+] Running 2/3 ⠿ Network code6-network Created 0.1s ⠿ Container code6-mysql Waiting 107.6s ⠿ Container code6-server Created 0.0s container for service "mysql" is unhealthy

运行环境

请复制 php doctor.php 运行结果

Could not open input file: doctor.php

报错日志

日志目录:storage/logs

yoonper commented 2 years ago

MySQL 容器创建失败,检查一下相关配置是否正确

lianghdx commented 2 years ago

这是我的配置文件:

# Web 映射到宿主机的端口
PORT=666

# MySQL 映射到宿主机的端口
MYSQL_PORT=3306

# MySQL 数据库名
MYSQL_DATABASE=code6

# MySQL 用户名
MYSQL_USER=root

# MySQL 密码
MYSQL_PASSWORD=123456

# MySQL 挂载到宿主机的目录
MYSQL_VOLUME_PATH=/home/liang/mysql

下面是mysql目录下的内容

2 下面是 php doctor.php 的运行结果

1

下面是运行报错的截图 3

yoonper commented 2 years ago

配置增加: MYSQL_ROOT_PASSWORD=xxx

lianghdx commented 2 years ago

加了还是报 mysql unhealthy

yoonper commented 2 years ago

docker-compose.yaml image: mysql/mysql-server 改为 image: mysql/mysql-server:5.7 MYSQL_USER 改为非 root 再试下

lianghdx commented 2 years ago

我弄好了,用的是我自己装的mysql8.x,不是docker的mysql