当我尝试在docker-compose文件上使用docker-compose up命令将此结果用作结果时,我想在Windows上使用docker容器在Windows上运行mysql。
> D:\dockerfiles>docker-compose up
db_1 | Initializing database
db_1 | 2018-10-08T09:00:29.024081Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
db_1 | 2018-10-08T09:00:29.024224Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
db_1 | 2018-10-08T09:00:29.024512Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1 | 2018-10-08T09:00:29.028590Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
db_1 | 2018-10-08T09:00:29.028673Z 0 [ERROR] Aborting
db_1 |
dockerfiles_db_1 exited with code 1
这是我的docker-compose.yml
version: '3.7'
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: pass
MYSQL_DATABASE: star
MYSQL_USER: user
MYSQL_PASSWORD: pass
更新docker compose文件
version: '3.7'
services:
mysqldb:
image: mysql:5.7
container_name: mysql_con1
command: --default-authentication-plugin=mysql_native_password
command: --disable-partition-engine-check
restart: always
environment:
MYSQL_ROOT_PASSWORD: pass
MYSQL_DATABASE: star
MYSQL_USER: user
MYSQL_PASSWORD: pass
volumes:
- "./:/var/lib/mysql"
networks:
- samplenet
networks:
samplenet:
driver: nat
答案 0 :(得分:1)
/var/lib/mysql
目录中有一些文件。从此目录中删除所有内容。
或者强烈建议使用docker-compose.yml
中的卷。
volumes:
- /my/own/datadir:/var/lib/mysql
更新: 我使用以下撰写文件进行了测试,该文件运行正常,没有任何错误。
version: '3.7'
services:
db:
image: mysql:5.7
restart: always
volumes:
- ./data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: pass
MYSQL_DATABASE: star
MYSQL_USER: user
MYSQL_PASSWORD: pass
答案 1 :(得分:0)
我总是在定义restaart = al时得到相同的行为,如果将其删除,一切正常,然后运行命令
docker update --restart=always {{ID OF CONTAINER}}
这使得它总是重新启动。希望对您有帮助。
答案 2 :(得分:0)
在docker-compose.yml中更新卷
volumes:
- /my/own/datadir:/var/lib/mysql
更新:此撰写文件运行正常。
mysql:
image: mysql:5.7.22
container_name: mysql
restart: unless-stopped
tty: true
ports:
- "3307:3306"
volumes:
- /my/own/datadir:/var/lib/mysql
environment:
MYSQL_USERNAME: "root"
MYSQL_PASSWORD: "root"
MYSQL_ROOT_PASSWORD: "root"
MYSQL_DATABASE: test