Set up fixed IP for Docker container to implement network Unicom

Source: Internet
Author: User
Tags git clone docker run

Goal

This blog has launched a series of content about Docker, I believe you have a strong interest in the container, but if you dive in, you may find that the difference between the container and the virtual machine is still relatively large, especially in the network, but also need a lot of improvement, of course, with the launch of the Docker 1.11 version , the network technology of the container is more and more perfect, next, we will give you a few we usually encounter some needs.

1, through pipework for Docker container set

For example

Host A and Host B are network unicom, creating multiple container clusters on host A, but I would like to have access to host A's container through Host B, and, of course, you might say, port mapping is very convenient, if I need more ports, or if I need to add some ports temporarily, May be set up more trouble, then if we will host a container inside the IP and host IP in the same network, can not be directly to the interconnection.


Steps

In fact, these needs in the past may need more complicated steps, for our network-born users more trouble, but Docker original engineers in the GitHub launched the Pipework tool, this tool can use a command can be implemented to change the container IP, More accurately to add a new network card for container IP, this is not a very good thing, thanks to open source.


Principle


Environment: (The right IP on the map should be 192.168.14.117, not changed)

VMWare Workstation 12

Ubuntu14.04

Docker1.10


The container virtual machine has two network adapters, eth0 and eth1,eth1 as management port 192.168.14.223, my notebook IP is equivalent to a network with the virtual machine another machine, IP is 192.168.14.117, my goal is to access the container virtual machine container instance through my notebook.


1. Create two container instances in container virtual machine

Here, I do not need the default Docker0 Network Bridge Assignment 172.17.0.1 network segment, so I set--net=none
[HTML] View plain copy root@controller:~# Docker run-d--name test1--net=none Ubuntu:14.04/bin/bash 711b9e0f1b3c7303d91cb750747ad723d1e3838983b352304 root@controller:~# Docker run-d--name test2 Ubuntu : 14.04/bin/bash ef5179fe1058cb71aa710642c9b6cb3417213e194e5c8d76ba0def28077ce267

2, Download pipework

[HTML] View plain copy git clone https://github.com/jpetazzo/pipework cp pipework/pipework/usr/local/bin/chmod +x /usr/local/bin/pipework


3. Next, set the fixed IP [HTML] view plain copy root@controller:~# pipework br0 test1 192.168.14.243/24@192.168.14 by the pipework command directly for the container .254 root@controller:~# Pipework Br0 test2 192.168.14.244/24@192.168.14.254 contains more than 200 lines of shell scripts, through pipework network Ace,veth pair and Linux Bridge complete the setup of the container network, and the execution process probably includes:

Check to see if the host contains BR0 (customizable) bridge, if not present create a test1 to the container instance (you can set the network card name) and configure the fixed ip:192.168.14.243 if test1 already has a default route, delete it. Connect the Test1 container instance to the created Br0 by setting the 192.168.14.254 after @ to the default route gateway

4, we enter the Test2 container to see if the IP has been set [html]  view plain  copy root@controller:~# docker ps -a    container id        image                COMMAND              CREATED              status              ports                NAMES   4940085f9358        ubuntu:14.04          "/bin/bash"          48 seconds ago       Up 48 seconds                            test2   19da8f983a5c        ubuntu:14.04          "/bin/bash"          54 seconds ago       Up 54 seconds                             test1   root@controller:~# docker exec -it 4940085f9358 /bin/bash    root@4940085f9358:/# ip a   1: LO: <LOOPBACK,UP,LOWER_UP> MTU  65536 qdisc noqueue state UNKNOWN group default  

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.