Docker officially recommends that we use port mapping to provide the services of the Docker container to the host or to other containers in the LAN. The general process is:
1. The Docker process packets the port data to the Docker container by listening to a port on a host
2, the host can open the firewall to allow other LAN devices to access the host port to access Docker port
But in practical use is not very convenient.
The following are recorded in the WIN10 Environment Squadron Dockerdocker Container exposed to the local area network by an independent IP.
In the default boot mode of Docker, a virtual network card is generated, and a separate network card and IP are allocated within the container. This virtual network card can be seen through the ipconfig command on the host.
Open a container and you can see that the container IP address is assigned automatically.
Cannot ping through host
IP interoperability by configuring routing tables
View Route print
View Docker's IP address
For 10.0.75.1 exposed to the host
Add route
Route-p add 172.17.0.0 MASK 255.255.255.0 10.0.75.2
Re-ping the container address
Now you can access it directly via IP.
Since Docker uses the bridge network by default, each time the container starts automatically assigns IP, we can create our own network Bridge1, specify the IP when the container is created, and add additional routes if a separate IP access is required.
Such as
Route-p add 172.18.12.0 MASK 255.255.255.0 10.0.75.2
If you delete a route:
Route Delete 172.18.12.0
The method of direct access of the Docker container intranet through independent IP