Help us understand the problem. What is going on with this article?

Docker for Macでコンテナからホストのサーバに接続する

More than 1 year has passed since last update.

概要

Dockerのコンテナの中からホスト(macOS)に接続したい場合、 host.docker.internal を使えばアクセスできます。

https://docs.docker.com/docker-for-mac/release-notes/#docker-community-edition-18030-ce-mac59-2018-03-26

DNS name host.docker.internal should be used for host resolution from containers. Older aliases (still valid) are deprecated in favor of this one. (See https://tools.ietf.org/html/draft-west-let-localhost-be-localhost-06).

動作確認

$ docker run -d -p 80:80 --name webserver nginx # nginxのサーバを立ち上げる
$ wget -O - http://localhost # localhostでつながる
$ docker run -it alpine sh # 適当なコンテナ立ち上げて中に入る

以下コンテナ内で実行

# wget -O - http://localhost # localhostではつながらない
# wget -O - http://host.docker.internal # これでつながる
rock619
「ご年齢に応じたご経験、スキルが不足されているようです」
https://rock619.com
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした