Docker Network access (iii)

Source: Internet
Author: User
Tags docker ps docker run

Docker Network access

Ifconfig look at the NIC, Docker will help us create a DOCKER0 bridge when we start Docker.

1. Random Mapping

    • Docker Run-p

2. Specify mappings

    • -P Hostport:containerport
    • -P Ip:hostPort:containerPort
    • -P Ip::containerport
    • -P HOSTPORT:CONTAINERPORT:UDP
    • -P hostport:containerport-p Hostport:containerport (multiple port mappings)

Random Map Case

Using Docker to start Nginx

[[email protected] ~]# Docker imagesrepository          TAG                 IMAGE ID            CREATED             sizenginx               latest              01f818af747d        2 weeks ago         181.6 mbcentos              latest              67591570dd29        4 weeks ago         191.8 Mb[[email Protected] ~]# Docker run-d-P Nginx 9725a9fb539a3334436c74a808f9ba134a8f530ed14065435f49846a7ecd4330[[email Protected] ~]# Docker pscontainer ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                           names9725a9fb539a        nginx               "nginx-g ' daemon off"   9 seconds ago up       5 seconds        0.0.0.0:10001-> 80/tcp, 0.0.0.0:10000->443/tcp   dreamy_gates

From the Docker PS command above you can see that the Nginx container starts, the 10001 of the physical machine is mapped to the 80 port of the container, and the 10000 of the physical machine is mapped to the 443 port of the container.

Access physical machine IP and port,http://192.168.137.11:10001/

Enter the Nginx container to view the network assigned address 172.17.0.2

[[email protected] ~]# Docker pscontainer ID IMAGE COMMAND CREATED  STATUS PORTS names9725a9fb539a Nginx "nginx-g ' Daemon off ' 9 minutes ago up 9 minutes 0.0.0.0:10001->80/tcp, 0.0.0.0:10000->443/tcp dreamy_gates [[email protected] ~]#./docker_in.sh 9725a9fb539a[email protected]:/# IP ad li1:lo: <LOOPBACK,UP,LOWER_ Up> MTU 65536 qdisc noqueue State UNKNOWN Group default Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00 in ET 127.0.0.1/8 scope host lo valid_lft forever Preferred_lft Forever Inet6:: 1/128 scope host Valid_lft fo Rever preferred_lft FOREVER20: [email protected]: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc Noqueue       State up group default Link/ether 02:42:ac:11:00:02 BRD ff:ff:ff:ff:ff:ff inet 172.17.0.2/16 Scope Global eth0 Valid_lft Forever PREFERRED_LFT forever inet6 fe80::42:acff:fe11:2/64 scope link Valid_lft forever Preferred_lft forever 

iptables view Nat table, command: iptables-t NAT-VNL

You can see the mapping between the container and the physical machine.

View Nginx Container Logs

[[email protected] ~]# Docker pscontainer ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                           names9725a9fb539a        nginx               "nginx-g ' daemon off"   minutes ago up      minutes       0.0.0.0:10001- >80/tcp, 0.0.0.0:10000->443/tcp   dreamy_gates[[email protected] ~]# Docker logs 9725a9fb539a

To specify a mapping case

1. Use Docker to start a nginx, specify 88 port

[email protected] ~]# Docker run-d-P 192.168.137.11:88:80--name Mynginx Nginxf807dc543291857aecd7ff9ebc7318039c6873e5c727cf71dbdd07d8ebac624a[[email protected] ~]# Docker PsCONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                namesf807dc543291        nginx               "nginx-g ' daemon Off"   4 seconds ago       up 2 seconds        443/tcp, 192.168.137.11:88->80/tcp   Mynginx

Hint:-D for background run-p specified port--name specified name

Visit Page http://192.168.137.11:88/

View Nginx Port Mappings

[email protected] ~]# Docker Port Mynginx80/tcp-192.168.137.11:88

2. Docker boot map multi-port

[email protected] ~]# Docker run-d-P 443:443-p 89:80--name mynginx2 Nginxe9e4eed824ddb26fa1abe742123e3c46515be775dbc5 C23556cefbaa94e92838[[email protected] ~]# Docker port mynginx2443/tcp-0.0.0.0:44380/tcp 0.0.0.0:89

Docker Network access (iii)

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.