Docker custom network and docker custom

Source: Internet
Author: User

Docker custom network and docker custom

Docker automatically creates three types of networks: none, host, and bridge. You can also customize networks as needed, including bridge, overlay, and macvlan. overlay and macvlan are cross-host networks.

Common sub-commands for docker network are as follows:

docker network createdocker network connectdocker network lsdocker network rmdocker network disconnectdocker network inspect

The default network is as follows:

Network Structure

Create a bridge network and specify the ip network segment (which can be automatically allocated)

docker network create --driver bridge --subnet 172.14.14.0/24 --gateway 172.14.14.1 net1

You can also see the br-c201be4aa4a6 after executing the ifconfig command

Allocate the added bridge network to the container

docker run -d --name httpd1 --network=net1 --ip 172.14.14.12 -p 8081:80 dbfc2cbe2971

Curl 172.14.14.12 can be accessed normally
Looking at the network structure, we will find that the new network interface is mounted to net1. vethaef4a02 is the virtual network card of the container.

After entering the container, you can see that the NIC is different from the preceding virtual Nic. The two are a pair of veth pair, which can be equivalent to a virtual network cable connecting a pair of NICs, one is a container and the other is net1, which is equivalent to adding the container Nic to net1.

Create another container 2

docker run -d --name httpd2 --network=net1 -p 8082:80 dbfc2cbe2971

Enter the container and ping the httpd1 ip address.

In the same network, containers and gateways can communicate normally.

Create container 3, default gateway docker0

docker run -d --name httpd3 -p 8083:80 dbfc2cbe2971

Then ping the ip address of container 1 to display failure, indicating that the two networks are independent.
If you want to allow container 3 to ping the ip address of container 1, you need to add container 3 to the network where container 1 is located.

docker network connect net1 httpd3

View ifconfig. eth1 is added to httpd3.

Then ping again.

In addition, you can ping the container name directly. (Embedded DNS server) can only communicate between container names in a custom network. By default, docker0 cannot communicate with each other by container name (dns is unavailable ).

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.