+-

我正在尝试将mysql添加到我的docker项目中,但我不断收到错误
db_1 | 2020-06-05T18:09:28.588053Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.20) initializing of server in progress as process 43
db_1 | 2020-06-05T18:09:28.611235Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
db_1 | 2020-06-05T18:09:28.611255Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
db_1 | 2020-06-05T18:09:28.613001Z 0 [ERROR] [MY-010119] [Server] Aborting
db_1 | 2020-06-05T18:09:28.613491Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.20) MySQL Community Server - GPL.
[我做docker ps
时看到
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9f561510f33d frontend "docker-entrypoint.s…" 4 minutes ago Up 4 minutes 0.0.0.0:3000->3000/tcp frontend_1
2c3f88dc6f6b backend "python3 manage.py r…" 5 minutes ago Up 5 minutes 0.0.0.0:8000->8000/tcp backend_1
d0768da38e93 mysql:latest "docker-entrypoint.s…" 5 minutes ago Restarting (1) 24 seconds ago db_1
我将容器var/lib
放入2c3f88dc6f6b
的CD中,但没有看到mysql目录。不知道是否可能是问题所在,但是如果这就是为什么没有mysql文件夹的原因?
为什么会看到该错误?
docker-compose.yml
version: "3.2"
services:
backend:
build: ./backend
volumes:
- ./backend:/app/backend
ports:
- "8000:8000"
stdin_open: true
tty: true
command: python3 manage.py runserver 0.0.0.0:8000
links:
- db
frontend:
build: ./frontend
volumes:
- ./frontend:/app
# One-way volume to use node_modules from inside image
- /app/node_modules
ports:
- "3000:3000"
environment:
- NODE_ENV=development
- CHOKIDAR_USEPOLLING=true
depends_on:
- backend
tty: true
command: npm start
db:
image: mysql:latest
restart: always
volumes:
- "./.mysql/db:/var/lib/mysql"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test
MYSQL_USER: root
MYSQL_PASSWORD: root
ports:
- "3306:3306"
0
投票
投票
当您尝试挂载卷并且对于您的环境变量,我正在使用Windows时,会出现此错误
mysql:
image: mysql:8.0.17
container_name: localmysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: 123456
ports:
- 3306:3306
volumes:
- C:\containers_data\mysql:/var/lib/mysql
其他意见:
您不需要在后端进行链接,只需将db
设为主机名 后端Depends_on db
检查我在github上的仓库:https://github.com/buster95/dockerinfra