The method of direct access of the Docker container intranet through independent IP

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.