I am trying to set up two containers one running Python, and the other mysql. This is my docker-compose.yml
file:
我正在尝试设置两个运行Python的容器,另一个运行mysql。这是我的docker-compose.yml文件:
version: '3'
services:
python:
restart: always
build: ./budget/dockerfiles/python/
ports:
- "5000:5000"
links:
- db
depends_on:
- db
volumes:
- ./budget/:/app:z
entrypoint:
- python
- -u
- /app/run.py
db:
build: ./budget/dockerfiles/mysql/
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: database-name
MYSQL_USER: root
MYSQL_PASSWORD: password
volumes:
- ./Dump.sql:/db/Dump.sql:z
- ./Dump_Test.sql:/db/Dump_Test.sql:z
- ./big_fc.sql:/db/big_fc.sql:z
ports:
- "3306:3306"
However, when I run docker-compose up -d --build
, the containers are built, but the mysql container crashes. In the log, it says:
但是,当我运行docker-compose up -d --build时,会构建容器,但是mysql容器崩溃了。在日志中,它说:
ERROR 1396 (HY000): Operation CREATE USER failed for 'root'@'%'
I wanted to try what this post suggests, but I cannot even enter the container since it is crashed. Can somebody tell me what I can do?
我想尝试一下这篇文章的建议,但我甚至无法进入容器,因为它已经崩溃了。有人能告诉我我能做什么吗?
1 个解决方案
#1
6
According to this github issue, the problem is setting MYSQL_USER
to root
. It will fail to create the second user 'root'@'%'
since it will already exist in the users table.
根据这个github问题,问题是将MYSQL_USER设置为root。它将无法创建第二个用户'root'@'%',因为它已存在于users表中。
Therefore, this can be solved by only setting MYSQL_ROOT_PASSWORD
, MYSQL_DATABASE
, and MYSQL_PASSWORD
in the docker-compose.yml
file.
因此,只需在docker-compose.yml文件中设置MYSQL_ROOT_PASSWORD,MYSQL_DATABASE和MYSQL_PASSWORD即可解决此问题。
#1
6
According to this github issue, the problem is setting MYSQL_USER
to root
. It will fail to create the second user 'root'@'%'
since it will already exist in the users table.
根据这个github问题,问题是将MYSQL_USER设置为root。它将无法创建第二个用户'root'@'%',因为它已存在于users表中。
Therefore, this can be solved by only setting MYSQL_ROOT_PASSWORD
, MYSQL_DATABASE
, and MYSQL_PASSWORD
in the docker-compose.yml
file.
因此,只需在docker-compose.yml文件中设置MYSQL_ROOT_PASSWORD,MYSQL_DATABASE和MYSQL_PASSWORD即可解决此问题。