28
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

docker, docker-composeでMySQLが起動しない

Last updated at Posted at 2018-11-20

原因

MYSQL_ROOT_PASSWORD が必須。

docker編

docker run -it --name mysql -d mysql

起動しない。

docker run -it --name mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -p 3306:3306 -d mysql

起動します。

docker-compose編

# docker-compose ps

     Name                         Command             State                                  
----------------------------------------------------------------
mysql_1_e6c3b5334932    docker-entrypoint.sh mysqld   Exit 1

起動してくれないと困るんじゃが。

> docker-compose logs | findstr mysql

Attaching to mysql_1_bff667044a7f, python_1_9815f4b12db2
error: database is uninitialized and password option is not specified
You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD

Windowsなのでfindstrになっていますが、Linuxならgrepです。

データベースが初期化されてないしパスワードオプションも指定してない というエラーでした。

docker-compose.yml
  mysql:
    image: mysql
    environment:
      MYSQL_DATABASE: dbname
      MYSQL_ROOT_PASSWORD: P@ssw0rd

そんな訳で、データベース名とパスワードオプションを指定して無事起動しました。 :tada:

28
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
28
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?