【问题标题】:Mysql container always restart itselfMysql 容器总是自行重启
【发布时间】:2020-08-19 03:11:07
【问题描述】:

我从镜像 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

【问题讨论】:

    标签: mysql database docker docker-compose containers


    【解决方案1】:

    如果容器失败了,但是它的restart policyunless-stopped...会重启:

    与always类似,除了当容器停止(手动或其他方式)时,即使在Docker daemon重启后也不会重新启动。

    注意:

    重启策略只有在容器启动成功后才会生效。在这种情况下,启动成功意味着容器至少启动了 10 秒,并且 Docker 已经开始对其进行监控。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-30
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 2021-06-24
      • 2019-03-30
      • 1970-01-01
      相关资源
      最近更新 更多