LoginSignup
0
0

More than 1 year has passed since last update.

Docker for windowsでローカルのドキュメントにループバック接続ができなかったときの解決法

Last updated at Posted at 2022-12-24

状況

あるコンテナをDocker for Windowsで立ち上げた。
ローカルの8080に置いたデータに対しlocalhost:8080からループバック接続を試みたが、404リクエストが返された。

コンテナの起動状況、ファイル設定等問題なく、エラーも出ていなかった。

原因

Stack Overflowの回答文から引用すると、

Answering to your first question (accessing docker container with localhost in docker for windows), in Windows host you cannot access the container with localhost due to a limitation in the default NAT network stack.
...
Seems like the docker documentation is not yet updated but this issue only exists in Windows hosts.

あなたの最初の質問(Docker for Windowsを利用して立てたコンテナにlocalhostを用いて接続をしたい)にお答えすると、WindowsホストはデフォルトのNATネットワークスタックの制限によりlocalhostを用いて接続することはできません。
...
dockerドキュメントはこの問題を網羅していないようですが、この問題はWindowsホストのみ発生するようです。

どうやらNATというものが干渉しているらしい。

解決法

dockerファイルのあるディレクトリにコマンドプロンプトから入り、

docker-compose up

を用いて起動することで解決した。
おそらくはDocker for Windows側からの起動には何らかのフィルタがかかっており、ループバック接続を弾いているのかなと考えています。

追記

ここではループバック接続にlocalhost:8080を使っていましたが、もしかしたらhost.docker.internal:8080から接続すればいけたかもしれません(おそらくこちらはdesctopによる起動も対応しているものと思われます)

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