0
1

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

Dockerのポート重複の解決

Posted at

複数のプロジェクトの同時並行でコンテナのポート番号が重複していたので解決法を備忘録

DB接続エラー 

私の場合,Laravel+MySQL環境にて,
MySQLコンテナのたえ3306番のポートを開いていたが追加で
同様の環境を立ち上げなくてはいけなくった
単にportsの設定でポートフォワーディングしただけでは不十分で,
SQLSTATE[HY000] [2002] Connection refusedのエラーとなってしまった

commandでポートを指定する

docker-comose.yml(だいぶ省略)
  mysql:
    build:
      context: ./
      dockerfile: ./docker/mysql/Dockerfile
    ports:
      - 3307:3307         ## ここだけでなく
    command: --port 3307  ## ここも追加

このようにコンテナ立ち上げ時にもport指定してあげる必要があります
(Docker run --port と同様)

あとは $ docker ps でポート3307に接続できているか確認してください

SQLSTATE[HY000] [2002] Connection refusedでググるとLaravelの.envとdocker-compose.ymlの設定を見直せと言う記事がよく出てきますが,
初心者はこっちの可能性もあるかも

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?