Use the bridge form under Docker

Source: Internet
Author: User

In order to use the Network Bridge in the form of Docker to access the intranet directly, you need to configure Docker, the actual test is as follows (need to pay attention to the Docker version of the problem)

# eth1:192.168.56.101

# eth2:192.168.58.101

# 192.168.56.0/24 Management Network

# 192.168.58.0/24 Data network, the network used by the container

# switch to the root user to execute the following command

1. Configure Linux Bridge

Brctl ADDBR Br0

IP addr Add 192.168.58.110/24 dev br0

# set an IP to the bridge so that the host can access the container directly

IP link set Dev br0 up

2. Configure the Docker daemon

Echo ' docker_opts= '-b=br0 ' >>/etc/default/docker

sudo service docker start

3. Start the container, set the network mode to none, configure the container network yourself

sudo docker run-it--net=none Ubuntu:14.04/bin/bash

4. View Container Process ID

Docker Inspect-f ' {. State.pid}} ' container_id

Pid=xxx

5. Create a namespaces directory

Mkdir-p/var/run/netns

Ln-s/proc/$pid/ns/net/var/run/netns/$pid

6. Create Veth device, assign to container, bind to bridge

IP link Add vetha type Veth peer name VETHB

Brctl addif br100 VETHB

IP link Set VETHB up

IP link set vetha netns $pid

IP netns exec $pid IP link set dev Vetha name eth0

IP netns exec $pid IP link set eth0 up

IP netns exec $pid IP addr add 192.168.58.121/24 dev eth0

IP netns exec $pid IP route add default via 192.168.58.110

7, bound eth2 to the bridge

Brctl addif br0 eth2

IP addr del 192.168.58.101/24 dev eth2 # remove eth2 IP

IP addr Add 192.168.58.101/24 dev br0 # Add eth2 IP to the bridge

Use the bridge form under Docker

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.