4x99 / code6

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

docker-compose模式安装失败 #215

Closed NS-Sp4ce closed 2 years ago

NS-Sp4ce commented 2 years ago

1.环境

CentOS Linux release 7.9.2009 (Core)
Docker version 20.10.17, build 100c701
docker-compose version 1.29.2, build unknown
Python 3.6

2.报错时的配置

.env.docker-compose


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

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

# MySQL 数据库名
MYSQL_DATABASE=code6

# MySQL 用户名
MYSQL_USER=root

# MySQL 密码
MYSQL_PASSWORD=root

# MySQL 挂载到宿主机的目录
MYSQL_VOLUME_PATH=/data

3.报错时的启动log(不带--verbose)

Building code6
Sending build context to Docker daemon  11.32MB
Step 1/13 : FROM php:7.4-apache
 ---> 702b8eb8639b
Step 2/13 : EXPOSE 80
 ---> Using cache
 ---> da4d91e297f3
Step 3/13 : ENV MYSQL_HOST="mysql"
 ---> Using cache
 ---> 1cdb411b8d12
Step 4/13 : ENV MYSQL_PORT="3306"
 ---> Using cache
 ---> f02bc2ed1ca7
Step 5/13 : ENV MYSQL_DATABASE="code6"
 ---> Using cache
 ---> 8b0a9d1e1ff0
Step 6/13 : ENV MYSQL_USERNAME="root"
 ---> Using cache
 ---> 1d4a9d185a46
Step 7/13 : ENV MYSQL_PASSWORD="root"
 ---> Using cache
 ---> 6bacd9d767c2
Step 8/13 : ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
 ---> Using cache
 ---> b57bf062198e
Step 9/13 : COPY . /var/www/html
 ---> Using cache
 ---> 3be2ae942e1c
Step 10/13 : COPY docker-entrypoint.sh docker-entrypoint.sh
 ---> Using cache
 ---> 8ac3fab9d1b8
Step 11/13 : WORKDIR /var/www/html
 ---> Using cache
 ---> babef66da897
Step 12/13 : RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak;echo 'deb http://mirrors.aliyun.com/debian buster main' >> /etc/apt/sources.list;echo 'deb http://mirrors.aliyun.com/debian buster-updates main' >> /etc/apt/sources.list;apt-get update;apt-get install -y --allow-downgrades zip cron vim zlib1g=1:1.2.11.dfsg-1 zlib1g-dev libpng-dev;rm -rf /var/lib/apt/lists/*;docker-php-ext-install pdo_mysql;docker-php-ext-install gd;sed -ri -e "s!/var/www/html!${APACHE_DOCUMENT_ROOT}!g" /etc/apache2/sites-available/*.conf;sed -ri -e "s!/var/www/!${APACHE_DOCUMENT_ROOT}!g" /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf;rm -rf /etc/localtime;ln -s /usr/share/zoneinfo/PRC /etc/localtime;echo "alias ll='ls -l'" >> /etc/bash.bashrc;echo 'set fileencodings=utf-8' >> /etc/vim/vimrc;echo 'set termencoding=utf-8' >> /etc/vim/vimrc;echo 'set encoding=utf-8' >> /etc/vim/vimrc;curl -sO https://mirrors.aliyun.com/composer/composer.phar;chmod +x composer.phar;mv composer.phar /usr/local/bin/composer;composer config repo.packagist composer https://mirrors.aliyun.com/composer/;composer install --no-dev --no-progress --optimize-autoloader;chmod +x docker-entrypoint.sh;
 ---> Using cache
 ---> 0eda1c1c8f1e
Step 13/13 : ENTRYPOINT /bin/bash docker-entrypoint.sh
 ---> Using cache
 ---> d302d37b5eb5
Successfully built d302d37b5eb5
Successfully tagged code6:latest
Creating code6-mysql ... done            <----这里会停很久

ERROR: for code6  Container "bc21ae177baa" is unhealthy.
ERROR: Encountered errors while bringing up the project.

docker ps

[root@localhost code6]# docker ps
CONTAINER ID   IMAGE                COMMAND                  CREATED         STATUS                            PORTS                                                        NAMES
bc21ae177baa   mysql/mysql-server   "/entrypoint.sh mysq…"   3 minutes ago   Up 3 minutes (health: starting)   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060-33061/tcp   code6-mysql

4.报错时的启动log(带--verbose,清空container、images安装)

compose.config.config.find: Using configuration files: ./docker-compose.yaml
compose.cli.docker_client.get_client: docker-compose version 1.29.2, build unknown
docker-py version: 5.0.3
CPython version: 3.6.8
OpenSSL version: OpenSSL 1.0.2k-fips  26 Jan 2017
compose.cli.docker_client.get_client: Docker base_url: http+docker://localhost
compose.cli.docker_client.get_client: Docker version: Platform={'Name': 'Docker Engine - Community'}, Components=[{'Name': 'Engine', 'Version': '20.10.17', 'Details': {'ApiVersion': '1.41', 'Arch': 'amd64', 'BuildTime': '2022-06-06T23:03:33.000000000+00:00', 'Experimental': 'false', 'GitCommit': 'a89b842', 'GoVersion': 'go1.17.11', 'KernelVersion': '3.10.0-1160.76.1.el7.x86_64', 'MinAPIVersion': '1.12', 'Os': 'linux'}}, {'Name': 'containerd', 'Version': '1.6.7', 'Details': {'GitCommit': '0197261a30bf81f1ee8e6a4dd2dea0ef95d67ccb'}}, {'Name': 'runc', 'Version': '1.1.3', 'Details': {'GitCommit': 'v1.1.3-0-g6724737'}}, {'Name': 'docker-init', 'Version': '0.19.0', 'Details': {'GitCommit': 'de40ad0'}}], Version=20.10.17, ApiVersion=1.41, MinAPIVersion=1.12, GitCommit=a89b842, GoVersion=go1.17.11, Os=linux, Arch=amd64, KernelVersion=3.10.0-1160.76.1.el7.x86_64, BuildTime=2022-06-06T23:03:33.000000000+00:00
compose.cli.verbose_proxy.proxy_callable: docker inspect_network <- ('code6-network')
compose.cli.verbose_proxy.proxy_callable: docker inspect_network -> {'Attachable': True,
 'ConfigFrom': {'Network': ''},
 'ConfigOnly': False,
 'Containers': {},
 'Created': '2022-08-19T00:49:53.964807414+08:00',
 'Driver': 'bridge',
 'EnableIPv6': False,
 'IPAM': {'Config': [{'Gateway': '172.18.0.1', 'Subnet': '172.18.0.0/16'}],
          'Driver': 'default',
          'Options': None},
...
compose.cli.verbose_proxy.proxy_callable: docker info <- ()
compose.cli.verbose_proxy.proxy_callable: docker info -> {'Architecture': 'x86_64',
 'BridgeNfIp6tables': True,
 'BridgeNfIptables': True,
 'CPUSet': True,
 'CPUShares': True,
 'CgroupDriver': 'cgroupfs',
 'CgroupVersion': '1',
 'ContainerdCommit': {'Expected': '0197261a30bf81f1ee8e6a4dd2dea0ef95d67ccb',
                      'ID': '0197261a30bf81f1ee8e6a4dd2dea0ef95d67ccb'},
 'Containers': 0,
...
compose.cli.verbose_proxy.proxy_callable: docker inspect_network <- ('code6-network')
compose.cli.verbose_proxy.proxy_callable: docker inspect_network -> {'Attachable': True,
 'ConfigFrom': {'Network': ''},
 'ConfigOnly': False,
 'Containers': {},
 'Created': '2022-08-19T00:49:53.964807414+08:00',
 'Driver': 'bridge',
 'EnableIPv6': False,
 'IPAM': {'Config': [{'Gateway': '172.18.0.1', 'Subnet': '172.18.0.0/16'}],
          'Driver': 'default',
          'Options': None},
...
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=False, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=False, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=mysql', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=mysql', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=code6', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=code6', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_image <- ('mysql/mysql-server')
compose.cli.verbose_proxy.proxy_callable: docker inspect_image -> {'Architecture': 'amd64',
 'Author': '',
 'Comment': '',
 'Config': {'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['mysqld'],
            'Domainname': '',
            'Entrypoint': ['/entrypoint.sh'],
            'Env': ['PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
...
compose.service.build: Building code6
Sending build context to Docker daemon  11.32MB
Step 1/13 : FROM php:7.4-apache
7.4-apache: Pulling from library/php
1efc276f4ff9: Pull complete 
3239fd0772e9: Pull complete 
52ccb8ba6c06: Pull complete 
e907707b68ee: Pull complete 
f001901b2b66: Pull complete 
3926f8e80674: Pull complete 
abc6b8b3381c: Pull complete 
f2aef5a590dd: Pull complete 
4739a6591a8b: Pull complete 
1c4c634ab8e6: Pull complete 
d84f48c0548d: Pull complete 
774f9d29e73c: Pull complete 
06e87fefb4ab: Pull complete 
Digest: sha256:495bf512c35efd33b601fc6d735f0f6a4a1313a7004d59fbcc15fda1de927021
Status: Downloaded newer image for php:7.4-apache
 ---> 702b8eb8639b
Step 2/13 : EXPOSE 80
 ---> Running in 93cc9fe1c091
Removing intermediate container 93cc9fe1c091
 ---> 6f0ea907de5e
Step 3/13 : ENV MYSQL_HOST="mysql"
 ---> Running in e3b695203b8b
Removing intermediate container e3b695203b8b
 ---> 8576a3b84d92
Step 4/13 : ENV MYSQL_PORT="3306"
 ---> Running in 67a9fc34da45
Removing intermediate container 67a9fc34da45
 ---> bc31377e8592
Step 5/13 : ENV MYSQL_DATABASE="code6"
 ---> Running in 1322f6668e71
Removing intermediate container 1322f6668e71
 ---> 8ac55e273d7a
Step 6/13 : ENV MYSQL_USERNAME="root"
 ---> Running in f927226be26b
Removing intermediate container f927226be26b
 ---> 79896cd14b24
Step 7/13 : ENV MYSQL_PASSWORD="root"
 ---> Running in 15dcaa2ecaeb
Removing intermediate container 15dcaa2ecaeb
 ---> 4866976ba3f8
Step 8/13 : ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
 ---> Running in 90d37e416f2c
Removing intermediate container 90d37e416f2c
 ---> 21170954e44d
Step 9/13 : COPY . /var/www/html
 ---> 38eb161bee7d
Step 10/13 : COPY docker-entrypoint.sh docker-entrypoint.sh
 ---> cf236dfa2e36
Step 11/13 : WORKDIR /var/www/html
 ---> Running in fe62d9fa6314
Removing intermediate container fe62d9fa6314
 ---> b4d14e6a22be
Step 12/13 : RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak;echo 'deb http://mirrors.aliyun.com/debian buster main' >> /etc/apt/sources.list;echo 'deb http://mirrors.aliyun.com/debian buster-updates main' >> /etc/apt/sources.list;apt-get update;apt-get install -y --allow-downgrades zip cron vim zlib1g=1:1.2.11.dfsg-1 zlib1g-dev libpng-dev;rm -rf /var/lib/apt/lists/*;docker-php-ext-install pdo_mysql;docker-php-ext-install gd;sed -ri -e "s!/var/www/html!${APACHE_DOCUMENT_ROOT}!g" /etc/apache2/sites-available/*.conf;sed -ri -e "s!/var/www/!${APACHE_DOCUMENT_ROOT}!g" /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf;rm -rf /etc/localtime;ln -s /usr/share/zoneinfo/PRC /etc/localtime;echo "alias ll='ls -l'" >> /etc/bash.bashrc;echo 'set fileencodings=utf-8' >> /etc/vim/vimrc;echo 'set termencoding=utf-8' >> /etc/vim/vimrc;echo 'set encoding=utf-8' >> /etc/vim/vimrc;curl -sO https://mirrors.aliyun.com/composer/composer.phar;chmod +x composer.phar;mv composer.phar /usr/local/bin/composer;composer config repo.packagist composer https://mirrors.aliyun.com/composer/;composer install --no-dev --no-progress --optimize-autoloader;chmod +x docker-entrypoint.sh;
 ---> Running in b314f566d20e
Get:1 http://mirrors.aliyun.com/debian buster InRelease [122 kB]
Get:2 http://mirrors.aliyun.com/debian buster-updates InRelease [56.6 kB]
Get:3 http://mirrors.aliyun.com/debian buster/main amd64 Packages [7911 kB]
........................环境安装省略
Removing intermediate container 3dbdeddb5d43
 ---> a36f9fae4930
Successfully built a36f9fae4930
Successfully tagged code6:latest
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=mysql', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=mysql', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.project._get_convergence_plans: code6 has upstream changes (mysql, mysql)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'status': ['created', 'exited'], 'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=code6', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'status': ['created', 'exited'], 'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=code6', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=False, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=code6', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=False, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=code6', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=code6', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=code6', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.parallel.feed_queue: Pending: {<Service: code6>, <Service: mysql>}
compose.parallel.feed_queue: Starting producer thread for <Service: mysql>
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=mysql', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=mysql', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
Creating code6-mysql ... 
compose.parallel.feed_queue: Pending: {ServiceName(project='code6', service='mysql', number=1)}
compose.parallel.feed_queue: Starting producer thread for ServiceName(project='code6', service='mysql', number=1)
compose.cli.verbose_proxy.proxy_callable: docker inspect_image <- ('mysql/mysql-server')
compose.cli.verbose_proxy.proxy_callable: docker inspect_image -> {'Architecture': 'amd64',
 'Author': '',
 'Comment': '',
 'Config': {'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['mysqld'],
            'Domainname': '',
            'Entrypoint': ['/entrypoint.sh'],
            'Env': ['PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
...
compose.cli.verbose_proxy.proxy_callable: docker inspect_image <- ('mysql/mysql-server')
compose.cli.verbose_proxy.proxy_callable: docker inspect_image -> {'Architecture': 'amd64',
 'Author': '',
 'Comment': '',
 'Config': {'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['mysqld'],
            'Domainname': '',
            'Entrypoint': ['/entrypoint.sh'],
            'Env': ['PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
...
compose.service.build_container_labels: Added config hash: cce9619fbc3f91861424d616134db0900e43e33c0c10b9bdde7cb3d87f56670b
compose.cli.verbose_proxy.proxy_callable: docker create_host_config <- (links=[], port_bindings={'3306/tcp': ['3306']}, binds=['/etc/localtime:/etc/localtime:ro', '/data:/var/lib/mysql:rw'], volumes_from=[], privileged=False, network_mode='code6-network', devices=None, device_requests=None, dns=None, dns_opt=None, dns_search=None, restart_policy={'Name': 'always', 'MaximumRetryCount': 0}, runtime=None, cap_add=None, cap_drop=None, mem_limit=None, mem_reservation=None, memswap_limit=None, ulimits=None, log_config={'Type': '', 'Config': {}}, extra_hosts=None, read_only=None, pid_mode=None, security_opt=None, ipc_mode=None, cgroup_parent=None, cpu_quota=None, shm_size=None, sysctls=None, pids_limit=None, tmpfs=None, oom_kill_disable=None, oom_score_adj=None, mem_swappiness=None, group_add=None, userns_mode=None, init=None, init_path=None, isolation=None, cpu_count=None, cpu_percent=None, nano_cpus=None, volume_driver=None, cpuset_cpus=None, cpu_shares=None, storage_opt=None, blkio_weight=None, blkio_weight_device=None, device_read_bps=None, device_read_iops=None, device_write_bps=None, device_write_iops=None, mounts=None, device_cgroup_rules=None, cpu_period=None, cpu_rt_period=None, cpu_rt_runtime=None)
compose.cli.verbose_proxy.proxy_callable: docker create_host_config -> {'Binds': ['/etc/localtime:/etc/localtime:ro', '/data:/var/lib/mysql:rw'],
 'Links': [],
 'LogConfig': {'Config': {}, 'Type': ''},
 'NetworkMode': 'code6-network',
 'PortBindings': {'3306/tcp': [{'HostIp': '', 'HostPort': '3306'}]},
 'RestartPolicy': {'MaximumRetryCount': 0, 'Name': 'always'},
 'VolumesFrom': []}
compose.cli.verbose_proxy.proxy_callable: docker create_container <- (environment=['PORT=666', 'MYSQL_PORT=3306', 'MYSQL_DATABASE=code6', 'MYSQL_USER=root', 'MYSQL_PASSWORD=root', 'MYSQL_VOLUME_PATH=/data'], healthcheck={'test': "mysql code6 -uroot -proot -e 'SELECT 1'", 'interval': 5000000000, 'retries': 40, 'start_period': 60000000000}, image='mysql/mysql-server', ports=[('3306', 'tcp')], volumes={'/etc/localtime': {}, '/var/lib/mysql': {}}, name='code6-mysql', detach=True, labels={'com.docker.compose.project': 'code6', 'com.docker.compose.service': 'mysql', 'com.docker.compose.oneoff': 'False', 'com.docker.compose.project.working_dir': '/root/code6', 'com.docker.compose.project.config_files': 'docker-compose.yaml', 'com.docker.compose.project.environment_file': '.env.docker-compose', 'com.docker.compose.container-number': '1', 'com.docker.compose.version': '1.29.2', 'com.docker.compose.config-hash': 'cce9619fbc3f91861424d616134db0900e43e33c0c10b9bdde7cb3d87f56670b'}, host_config={'NetworkMode': 'code6-network', 'RestartPolicy': {'Name': 'always', 'MaximumRetryCount': 0}, 'VolumesFrom': [], 'Binds': ['/etc/localtime:/etc/localtime:ro', '/data:/var/lib/mysql:rw'], 'PortBindings': {'3306/tcp': [{'HostIp': '', 'HostPort': '3306'}]}, 'Links': [], 'LogConfig': {'Type': '', 'Config': {}}}, networking_config={'EndpointsConfig': {'code6-network': {'Aliases': ['mysql'], 'IPAMConfig': {}}}})
compose.cli.verbose_proxy.proxy_callable: docker create_container -> {'Id': '1f641840fc949329a46e0c1a3e9ca42bd3f83c67c350564bdf7585b66f4e2587',
 'Warnings': []}
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('1f641840fc949329a46e0c1a3e9ca42bd3f83c67c350564bdf7585b66f4e2587')
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {'AppArmorProfile': '',
 'Args': ['mysqld'],
 'Config': {'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['mysqld'],
            'Domainname': '',
            'Entrypoint': ['/entrypoint.sh'],
            'Env': ['PORT=666',
                    'MYSQL_PORT=3306',
...
compose.cli.verbose_proxy.proxy_callable: docker disconnect_container_from_network <- ('1f641840fc949329a46e0c1a3e9ca42bd3f83c67c350564bdf7585b66f4e2587', 'code6-network')
compose.cli.verbose_proxy.proxy_callable: docker disconnect_container_from_network -> None
compose.cli.verbose_proxy.proxy_callable: docker connect_container_to_network <- ('1f641840fc949329a46e0c1a3e9ca42bd3f83c67c350564bdf7585b66f4e2587', 'code6-network', aliases=['1f641840fc94', 'mysql'], ipv4_address=None, ipv6_address=None, links=[], link_local_ips=None)
compose.parallel.feed_queue: Pending: {<Service: code6>}
compose.cli.verbose_proxy.proxy_callable: docker connect_container_to_network -> None
compose.cli.verbose_proxy.proxy_callable: docker start <- ('1f641840fc949329a46e0c1a3e9ca42bd3f83c67c350564bdf7585b66f4e2587')
compose.parallel.feed_queue: Pending: set()
compose.parallel.feed_queue: Pending: {<Service: code6>}
compose.parallel.feed_queue: Pending: set()
compose.parallel.feed_queue: Pending: {<Service: code6>}
compose.parallel.feed_queue: Pending: set()
compose.parallel.feed_queue: Pending: {<Service: code6>}
compose.parallel.feed_queue: Pending: set()
compose.parallel.feed_queue: Pending: {<Service: code6>}
compose.parallel.feed_queue: Pending: set()
compose.parallel.feed_queue: Pending: {<Service: code6>}
compose.parallel.feed_queue: Pending: set()
compose.parallel.feed_queue: Pending: {<Service: code6>}
compose.parallel.feed_queue: Pending: set()
compose.cli.verbose_proxy.proxy_callable: docker start -> None
Creating code6-mysql ... done
compose.parallel.feed_queue: Pending: set()
compose.parallel.parallel_execute_iter: Finished processing: <Service: mysql>
compose.parallel.feed_queue: Pending: {<Service: code6>}
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=False, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=mysql', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 1 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('1f641840fc949329a46e0c1a3e9ca42bd3f83c67c350564bdf7585b66f4e2587')
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {'AppArmorProfile': '',
 'Args': ['mysqld'],
 'Config': {'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['mysqld'],
            'Domainname': '',
            'Entrypoint': ['/entrypoint.sh'],
            'Env': ['PORT=666',
                    'MYSQL_PORT=3306',
...
compose.parallel.feed_queue: Pending: {<Service: code6>}
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=False, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=mysql', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 1 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('1f641840fc949329a46e0c1a3e9ca42bd3f83c67c350564bdf7585b66f4e2587')
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {'AppArmorProfile': '',
 'Args': ['mysqld'],
 'Config': {'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['mysqld'],
            'Domainname': '',
            'Entrypoint': ['/entrypoint.sh'],
            'Env': ['PORT=666',
                    'MYSQL_PORT=3306',
...
compose.parallel.feed_queue: Pending: {<Service: code6>}
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=False, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=mysql', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 1 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('1f641840fc949329a46e0c1a3e9ca42bd3f83c67c350564bdf7585b66f4e2587')
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {'AppArmorProfile': '',
 'Args': ['mysqld'],
 'Config': {'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['mysqld'],
            'Domainname': '',
            'Entrypoint': ['/entrypoint.sh'],
            'Env': ['PORT=666',
                    'MYSQL_PORT=3306',
...
compose.parallel.feed_queue: Pending: {<Service: code6>}
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=False, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=mysql', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 1 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('1f641840fc949329a46e0c1a3e9ca42bd3f83c67c350564bdf7585b66f4e2587')
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {'AppArmorProfile': '',
 'Args': ['mysqld'],
 'Config': {'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['mysqld'],
            'Domainname': '',
            'Entrypoint': ['/entrypoint.sh'],
            'Env': ['PORT=666',
                    'MYSQL_PORT=3306',
...
compose.parallel.feed_queue: Pending: {<Service: code6>}
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=False, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=mysql', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 1 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('1f641840fc949329a46e0c1a3e9ca42bd3f83c67c350564bdf7585b66f4e2587')
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {'AppArmorProfile': '',
 'Args': ['mysqld'],
 'Config': {'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['mysqld'],
            'Domainname': '',
            'Entrypoint': ['/entrypoint.sh'],
            'Env': ['PORT=666',
                    'MYSQL_PORT=3306',
...
compose.parallel.feed_queue: Pending: {<Service: code6>}
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=False, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=mysql', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 1 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('1f641840fc949329a46e0c1a3e9ca42bd3f83c67c350564bdf7585b66f4e2587')
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {'AppArmorProfile': '',
 'Args': ['mysqld'],
 'Config': {'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['mysqld'],
            'Domainname': '',
            'Entrypoint': ['/entrypoint.sh'],
            'Env': ['PORT=666',
                    'MYSQL_PORT=3306',
...
compose.parallel.feed_queue: Pending: {<Service: code6>}
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=False, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=mysql', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 1 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('1f641840fc949329a46e0c1a3e9ca42bd3f83c67c350564bdf7585b66f4e2587')
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {'AppArmorProfile': '',
 'Args': ['mysqld'],
 'Config': {'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['mysqld'],
            'Domainname': '',
            'Entrypoint': ['/entrypoint.sh'],
            'Env': ['PORT=666',
                    'MYSQL_PORT=3306',
...

--verbose启动时会打印出启动失败前的日志,观察到存在大量的如下日志

compose.parallel.feed_queue: Pending: {<Service: code6>}
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=False, filters={'label': ['com.docker.compose.project=code6', 'com.docker.compose.service=mysql', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 1 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('1f641840fc949329a46e0c1a3e9ca42bd3f83c67c350564bdf7585b66f4e2587')
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {'AppArmorProfile': '',
 'Args': ['mysqld'],
 'Config': {'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['mysqld'],
            'Domainname': '',
            'Entrypoint': ['/entrypoint.sh'],
            'Env': ['PORT=666',
                    'MYSQL_PORT=3306',
...

4.已尝试如下配置

  1. 更改docker的DNS ----无效
  2. 延长healthcheck时间和次数 ----无效
NS-Sp4ce commented 2 years ago

已解决,更改docker-compose.yaml为如下

version: "3.9"
services:
  mysql:
    image: mysql/mysql-server:5.7
    container_name: code6-mysql
    restart: always
    env_file:
      - .env.docker-compose
    networks:
      - code6-network
    ports:
      - ${MYSQL_PORT}:3306
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ${MYSQL_VOLUME_PATH}:/var/lib/mysql
    healthcheck:
      test: mysql ${MYSQL_DATABASE} -u${MYSQL_USER} -p${MYSQL_PASSWORD} -e 'SELECT 1'
      interval: 5s
      retries: 10
      start_period: 60s
  code6:
    image: code6
    build:
      context: .
      dockerfile: Dockerfile
    container_name: code6-server
    depends_on:
      mysql:
        condition: service_healthy
    restart: always
    env_file:
      - .env.docker-compose
    environment:
      MYSQL_HOST: mysql
      MYSQL_PORT: 3306
      MYSQL_USERNAME: ${MYSQL_USER}
    ports:
      - ${PORT}:80
    networks:
      - code6-network
    links:
      - mysql
networks:
  code6-network:
    name: code6-network

.env.docker-compose为如下


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

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

# MySQL 数据库名
MYSQL_DATABASE=code6

# MySQL 用户名
MYSQL_USER=root

# MySQL 密码
MYSQL_PASSWORD=root
MYSQL_ROOT_PASSWORD=root

# MySQL 挂载到宿主机的目录
MYSQL_VOLUME_PATH=/data

``
启动成功