简体   繁体   English

Mysql docker 容器不断重启

[英]Mysql docker container keeps restarting

The Container keeps restarting.容器不断重启。 I tried我试过了

  • docker-compose down -v docker-compose 向下 -v
  • docker volume rm docker 体积rm

The container was working fine until my pc got accidentally shutdown.容器工作正常,直到我的电脑意外关机。

Logs日志

2021-03-27 13:16:08+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.

2021-03-27 13:16:08+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'

2021-03-27 13:16:08+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.

2021-03-27 13:16:08+00:00 [ERROR] [Entrypoint]: MYSQL_USER="root", MYSQL_USER and MYSQL_PASSWORD are for configuring a regular user and cannot be used for the root user

Remove MYSQL_USER="root" and use one of the following to control the root user password:

- MYSQL_ROOT_PASSWORD

- MYSQL_ALLOW_EMPTY_PASSWORD

- MYSQL_RANDOM_ROOT_PASSWORD

Docker-compose.yml Docker-compose.yml

 mysql:
    image: mysql:8.0
    ports:
      - 3306:3306
    expose:
      - "3306"
    cap_add:
      - SYS_NICE # CAP_SYS_NICE
    volumes:
      - ./cache/mysql:/var/lib/mysql
      - ./conf-mysql.cnf:/etc/mysql/conf.d/mysql.cnf
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_PASSWORD=root
      - MYSQL_USER=root
      - MYSQL_DATABASE=mydb
    restart: unless-stopped

Simply remove the MYSQL_USER and it will work fine because the root user gets created automatically.只需删除MYSQL_USER ,因为root用户是自动创建的。

PS. PS。 This seems to be a problem with a newer docker version because this used to work before and not throw an error.这似乎是较新的 docker 版本的问题,因为它以前可以工作并且不会引发错误。

User root is reserved and already created with mysql when it's up.用户root已保留,并且在启动时已使用 mysql 创建。

MYSQL_USER must be a different name, not root . MYSQL_USER必须是不同的名称,而不是root

I faced the exact same problem and here is how I fixed it.我遇到了完全相同的问题,这就是我解决它的方法。

Go to your docker-compose.yml file and make the following changes: Go 到您的 docker-compose.yml 文件并进行以下更改:

  • "MYSQL_USER: root" to "MYSQL_ROOT_USER: root" then delete the previous one. “MYSQL_USER:root”改为“MYSQL_ROOT_USER:root”然后删除前一个。

  • "MYSQL_PASSWORD: YourPasseord" to "MYSQL_ROOT_PASSWORD: YourPasseord" then delete the previous one. "MYSQL_PASSWORD: YourPasseord" 改为 "MYSQL_ROOT_PASSWORD: YourPasseord" 然后删除前一个。

    Example:Here is my configuration...示例:这是我的配置...

database_server:数据库服务器:

image: mysql:8.0
       container_name: mysql
       restart: always
       environment:
         MYSQL_DATABASE: DB_epraca
         MYSQL_ROOT_USER: root
         MYSQL_ROOT_PASSWORD: Password
         MYSQL_ROOT_HOST: localhost

Only update your the.env file:仅更新您的 .env 文件:

DB_USERNAME=sail
DB_PASSWORD=password

There was recent change how the official mysql docker which caused this issue.最近官方 mysql docker 的变化导致了这个问题。 For further details you can check this PR on github .有关更多详细信息,您可以在 github 上查看此 PR

For a quick solution you should remove MYSQL_USER=root and your docker-compose.yaml file should look something like this对于快速解决方案,您应该删除MYSQL_USER=root并且您的docker-compose.yaml文件应该看起来像这样

mysql:
    image: mysql:8.0
    ports:
      - 3306:3306
    expose:
      - "3306"
    cap_add:
      - SYS_NICE # CAP_SYS_NICE
    volumes:
      - ./cache/mysql:/var/lib/mysql
      - ./conf-mysql.cnf:/etc/mysql/conf.d/mysql.cnf
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=mydb
    restart: unless-stopped

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM