https://docs.docker.com/desktop/windows/networking/

 

Networking features in Docker Desktop for Windows

 

docs.docker.com

Features

Port Mapping: -p HOST_PORT:CLIENT_PORT

$ docker run -p 8000:80 -d nginx

connections to localhost:8000 are sent to port 80 in the container.

 

Known limitations, use cases, and workarounds

There is no docker0 bridge on Windows

 

I cannot ping my containers

 

Per-container IP addressing is not possible

 

Use cases and workarounds

I want to connect from a container to a service on the host

The host has a changing IP address (or none if you have no network access).

We recommend that you connect to the special DNS name host.docker.internal

which resolves to the internal IP address used by the host.

This is for development purpose and will not work in a production environment outside of Docker Desktop for Windows.

 

You can also reach the gateway using gateway.docker.internal.

 

Example:

1. Run the following command to start a simple HTTP server on port 8000.

python -m http.server 8000

2. Now, run a container, install curl, and try to connect to the host using the following commands:

$ docker run --rm -it alpine sh
# apk add curl
# curl http://gateway.docker.internal:8000
# exit

curl http://host.docker.internal:8000
curl http://gateway.docker.internal:8000

I want to connect to a container from Windows

Port forwarding works for localhost; --publish, -p, or -P all work.

Ports exposed from Linux are forwarded to the host.

Our current recommendation is to publish a port, or to connect from another container.

This is what you need to do even on Linux if the container is on an overlay network, not a bridge network, as these are not routed.

For example, to run an nginx webserver:

$ docker run -d -p 80:80 --name webserver nginx

To clarify the syntax, the following two commands both publish container's port 80 to host's port 8000:

$ docker run --publish 8000:80 --name webserver nginx

$ docker run -p 8000:80 --name webserver nginx

To publish all ports, use the -P flag.

For example, the following command starts a container (in detached mode) and the -P flag publishes all exposed ports of the container to random ports on the host.

$ docker run -d -P --name webserver nginx

 

'OS > Docker' 카테고리의 다른 글

Docker Desktop Tips  (0) 2021.10.12

Windows 기능 설정

가상화 지원 확인

System requirements

WSL 2 backend / Hyper-V backend and Windows Containers

  • Enable the WSL 2 feature on Windows.
  • Hyper-V and Containers Windows features must be enabled.
  • The following H/W prerequisites are required to successfully run WSL 2/Client Hyper-V on Windows 10:
    • 64-bit processor with Second Level Address Translation (SLAT)
    • 4GB system RAM
    • BIOS-level hardware virtualization support must be enabled in the BOIS settings.
  • Download and install the Linux kernel update package.

 

  •  

'OS > Docker' 카테고리의 다른 글

Networking features in Docker Desktop for Windows  (0) 2021.10.13

+ Recent posts