This article is a mirror article of machine translation, please click here to jump to the original article.

View: 8012|Reply: 0

Docker container setting up a fixed IP tutorial

[Copy link]
Posted on 9/28/2018 10:17:37 AM | | | |
Often using Docker to simulate the deployment of a project in a production environment, it is often necessary to open several Docker containers at the same time, and sometimes the installed software needs to be bound to other containers in the Docker LAN, such as MongoDB replica set deployment, it needs to bind the private IP of other containers.

However, after each Docker restart, the IP address of the container will change, and Docker supports setting a fixed IP after querying the data.

Docker default network

Once Docker is installed, the following three network types are created by default:

NETWORK ID          NAME                DRIVER              SCOPE
17cbf438c338        bridge              bridge              local
1ac50740d496        host                host                local
e863b9972d3b        none                null                local
bridge: Bridge network

By default, the Docker containers started use bridges, the bridge network created when Docker is installed, and every time the Docker container is restarted, the corresponding IP address will be obtained in order, which will cause the Docker IP address to change under the restart

none: No network is specified

With --network=none, the docker container does not assign IP for the LAN

host: host network

With --network=host, the Docker container's network is attached to the host, and the two are interoperable.
For example, if you run a web service in a container and listen to port 8080, the host's port 8080 will be automatically mapped to the container.

Create a custom network: (Set a fixed IP)

Step 1: Create a custom network

Create a custom network and specify the CIDR block: 172.18.0.0/16


Step 2: Create a Docker container

At this time, the created Docker container will hold 172.18.0.2 this IP.








Previous:How to get the IP address of a docker container
Next:Oracle views the structure of the table through SQL
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com