Mysql容器总是自行重启

问题描述

我从映像MysqL制作了容器,但是该容器无法运行该容器。总是自己重启

我的docker-compose.yml:

MysqL:
        image: MysqL:latest
        container_name: MysqL 
        restart: unless-stopped
        tty: true
        ports: 
            - "3306:3306"
        volumes: 
            - ./MysqL:/var/lib/MysqL
        environment: 
            MysqL_DATABASE: laravel
            MysqL_USER: root
            MysqL_PASSWORD: 
            MSYQL_ROOT_PASSWORD:
            SERVICE_TAG: dev
            SERVICES_NAME: MysqL
        networks: 
            - laravel

当我尝试使用命令docker logs --tail 50 --follow --timestamps MysqL时,我得到了这个

2020-08-19T02:55:23.433654365Z 2020-08-19 02:55:23+00:00 [Note] [Entrypoint]: Entrypoint script for MysqL Server 8.0.21-1debian10 started.
2020-08-19T02:55:23.806507100Z 2020-08-19 02:55:23+00:00 [Note] [Entrypoint]: Switching to dedicated user 'MysqL'
2020-08-19T02:55:23.829003854Z 2020-08-19 02:55:23+00:00 [Note] [Entrypoint]: Entrypoint script for MysqL Server 8.0.21-1debian10 started.
2020-08-19T02:55:24.171193704Z 2020-08-19 02:55:24+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specified
2020-08-19T02:55:24.171719392Z  You need to specify one of MysqL_ROOT_PASSWORD,MysqL_ALLOW_EMPTY_PASSWORD and MysqL_RANDOM_ROOT_PASSWORD
2020-08-19T02:55:29.345542908Z 2020-08-19 02:55:29+00:00 [Note] [Entrypoint]: Entrypoint script for MysqL Server 8.0.21-1debian10 started.
2020-08-19T02:55:29.728781351Z 2020-08-19 02:55:29+00:00 [Note] [Entrypoint]: Switching to dedicated user 'MysqL'
2020-08-19T02:55:29.763193498Z 2020-08-19 02:55:29+00:00 [Note] [Entrypoint]: Entrypoint script for MysqL Server 8.0.21-1debian10 started.
2020-08-19T02:55:30.181369167Z 2020-08-19 02:55:30+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specified
2020-08-19T02:55:30.181429655Z  You need to specify one of MysqL_ROOT_PASSWORD,MysqL_ALLOW_EMPTY_PASSWORD and MysqL_RANDOM_ROOT_PASSWORD

解决方法

如果容器失败,但其 restart policy unless-stopped ...,它将重新启动:

与以往类似,只是在容器停止(手动或其他方式)时,即使重新启动Docker守护程序也不会重新启动容器。

请注意:

重新启动策略仅在容器成功启动后才生效。在这种情况下,成功启动意味着该容器已启动至少10秒钟,并且Docker已开始对其进行监视。

因此,在您的情况下,这应该不适用(由于日志时间戳记仅显示几秒钟),但是对于测试,您仍然可以检查将重启设置为no是否可以避免该循环。