LoginSignup
0
1

dockerでMySQLが立ち上がらなかったのを解決した話

Last updated at Posted at 2024-02-16

普段通り $ docker-compose up -bを実行してコンテナを起動しようとしたところ、立ち上がってすぐにstatusがExitedになってしまい、コンテナが立ち上がらなかった。

コンテナのログを見てみると

ログ
[Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.44-1.el7 started.
[Note] [Entrypoint]: Switching to dedicated user 'mysql'
[Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.44-1.el7 started.
[Note] [Entrypoint]: Initializing database files
[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
[ERROR] --initialize specified but the data directory has files in it. Aborting.
[ERROR] Aborting

と出力されている。

どうやらこの
[ERROR] --initialize specified but the data directory has files in it. Aborting.がエラーメッセージのよう。。

dbが重複して立ち上がっている?

こちらの記事を参照したところ、重複して使われているものがあると立ち上がらないとのこと。
dockerでMySQLが立ち上がらない時の対処法 --initialize specified but the data directory has files in it. Aborting

こちらに記載のコマンドを試してみたが、ダメだった。

docker system prune --volumes

volumeを削除する

ボリュームを手動で削除することにした。
ボリュームを削除すると今までの DBに保存されている情報は削除されてしまうので注意。
必要であればバックアップが必要。

私の場合はローカル環境で特に影響がなかったので問題なし

データボリュームを確認:

$ docker volume ls

データボリュームを削除:

docker volume rm <volume_name>

コンテナを再起動:

docker-compose up -b build

これで無事にdbのコンテナを立ち上げることができました!

0
1
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
0
1