Docker container sets static IP to communicate with host on same network segment

Source: Internet
Author: User
Tags docker ps docker run

The Docker container was used to set static IP addresses and communication between containers and containers, so there was not much to record.

See an article on the internet today about setting up a static IP address. On their own in the actual situation. Yes, there's a pipework that can also be set.


Operating system environment
[Email protected]:~# cat/etc/issueubuntu 14.04.3 LTS \ \l

Host (the system uses UBUNTU-14.04.1-SERVER-AMD64) network with bridge mode (the default is the DHCP mode, there is a mode is static IP), the network segment of the bridge is the same as the physical network segment. The current physical network segment is 192.168.75.0/24, the gateway is 192.168.75.2, the physical network card device is eth0

Edit the configuration file/etc/network/interfaces, customize the bridge Br0, modify the contents as follows

[Email protected]:~# tail-n8/etc/network/interfacesauto br0ifacebr0 inet static address 192.168.75.131 netmask 255 .255.255.0 Gateway 192.168.75.2 bridge_ports eth0 bridge_stp off Dns-nameservers 192.168.75.2

After you save the exit, restart the network

[Email protected]:~# ifdown-a && ifup-a

Use the Ifconfig command to view network interface information, host IP address 192.168.75.131

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M01/80/29/wKioL1c5y_PSRnOZAAHjIDayFdk885.jpg "title=" 1.jpg " alt= "Wkiol1c5y_psrnozaahjidayfdk885.jpg"/>

Once the bridge is configured, then configure the Docker network configuration.
    • The container start network mode must be none, specified with-net=none, as shown below

[Email protected]:~# Docker run-itd--name X6--net=none UBUNTU/BIN/BASH142CBE651CB7289EDBC0FA8804E135908C75FB7AC26CF 474f55c5e7786049bfb

Note: Docker container ID can be shortened by a long time, using Docker PS can also see the container ID, such as the following

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M02/80/2C/wKiom1c5yziT6TpjAACkdEPMfe8904.jpg "title=" 2.jpg " alt= "Wkiom1c5yzit6tpjaackdepmfe8904.jpg"/>

    • To set a static IP address for a new running container, a buddy on the web uses a script to configure the IP and then input parameters, I am directly using its SCRIPTS,142CBE651CB7 container id,24 bitmask, 192.168.75.2 Gateway. Examples such as the following

[Email protected]:~# sh static_ip.sh 142cbe651cb7 192.168.75.199 24 192.168.75.2

Ping the static ip192.168.75.199 set for the container x6

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M02/80/2C/wKiom1c5y23yRQbuAADJ3RTW-Rw708.jpg "title=" 1.jpg " alt= "Wkiom1c5y23yrqbuaadj3rtw-rw708.jpg"/>

    • Enter the container name X6, view the next IP address

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/80/29/wKioL1c5zG_QdaYaAAGdGqPWJg8053.jpg "title=" 2.jpg " alt= "Wkiol1c5zg_qdayaaagdgqpwjg8053.jpg"/>

Note: After the Docker container restarts, the IP address is on the meter.

The script content is as follows

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M01/80/29/wKioL1c5zKHQQ9URAAHhgtBVzo8598.jpg "title=" 1.jpg " alt= "Wkiol1c5zkhqq9uraahhgtbvzo8598.jpg"/>



This article is from the "Village Boys" blog, please make sure to keep this source http://noodle.blog.51cto.com/2925423/1774081

Docker container sets static IP to communicate with host on the same network segment

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.