8
5

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 5 years have passed since last update.

docker-compose up -dの実行で、port is already allocatedとのエラーが出た時の対処法

Last updated at Posted at 2019-08-31

dockerを起動させようと$ docker-compose up -dコマンドを入力すると、次のエラーが出ました。

Bind for 0.0.0.0:3306 failed: port is already allocated
ERROR: Encountered errors while bringing up the project.

これは、すでに3306のポートは既に割り当てられているので、利用できません、無理ですと言う意味。
利用状況を次のコマンドで確認すると、次のように確かに使用されていることがわかる。

$ sudo lsof -i:3306
Password:
COMMAND    PID   USER   FD   TYPE    DEVICE SIZE/OFF NODE NAME
com.docke 64339         14u  IPv6    0t0  TCP *:mysql (LISTEN)

対処法1

不要なポートであれば削除して、新たに設定する。

$ sudo kill 64339           #PIDの数値を記入
Password:
$ docker-compose up -d      #再度dockerを起動

対処法2

ポート番号を変更して起動する。

docker-compose.yml
version: '3.2'

services:

  <中略>

    ports:
      - 3300:3306     #自分のPCのポート:仮想環境の中のポート
   
 <中略>

volumes:
  
 <中略>

接続確認

最後に、MySQLの接続の確認が取れればOK。exit;で抜ける。

$ mysql -u root -p -h 127.0.0.1

 <中略>

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql >
8
5
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
8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?