docker工作但docker-compose失败

时间:2018-03-18 12:57:59

标签: mysql docker docker-compose

我正在使用mysql docker image,这有效:

docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=12345678 -d mysql:5.7.21

现在我想把它变成一个docker-compose yml文件:

version: "3"
services: 

  mysql:
   image: mysql:5.7.21
  environment:
  - MYSQL_ROOT_PASSWORD:12345678
  container_name: some-mysql

当docker-compose时,它显示以下错误:

Recreating test-mysql
Attaching to some-mysql
some-mysql | error: database is uninitialized and password option is not specified 
some-mysql |   You need to specify one of MYSQL_ROOT_PASSWORD,   MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD

some-mysql退出代码1

任何想法为什么?

1 个答案:

答案 0 :(得分:0)

environment文件的docker-compose.yaml块中存在错误。

根据docker compose文档,environment块应该是:

environment:
  - MYSQL_ROOT_PASSWORD=12345678

environment:
  MYSQL_ROOT_PASSWORD: 12345678