dockerのコンテナを起動させるために、いつも通りdocker compose up -d
したところ、以下のようなエラーが出た。
[+] Running 2/3
✔ Container app_laravel Started 0.3s
✔ Container test_phpmyadmin Started 0.3s
⠸ Container db Starting 0.3s
Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:3306 -> 0.0.0.0:0: listen tcp 0.0.0.0:3306: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.
原因と解決策
他のアプリにポート番号3306番が使われているのでは...?
と思い、データベース関連のアプリが裏で動いているのではと考え、Windowsのタスクマネージャーを調査。
mysqldが動いてた。
なので、タスクマネージャーから「タスクの終了」でアプリを強制終了(これはdockerだけど)。
そして再度docker compose up -d
を実行。
[+] Running 4/4
✔ Container app_laravel Running 0.0s
✔ Container test_phpmyadmin Running 0.0s
✔ Container nginx Started 0.4s
✔ Container db Started 0.4s
動いた!!!
Ports are not availableと言われたら、ポートの競合を疑ってみると◎ということを学べた。
参考記事