In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to configure the docker network". Many people will encounter such a dilemma in the operation of the actual case. then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The steps for Docker to configure the container are:
1. Create a pair of virtual interfaces
two。 Give it a unique name inside the main Docker host, such as veth75f9, and bind it to any bridge used by docker0 or Docker
3. Let the other interfaces climb over the wall and enter the new container (the lo interface is already provided). In the container's independent and unique network interface namespace, rename it to the prettier name eth0, which does not conflict with other physical interfaces.
4. Give the container's eth0 a new IP address within the bridge's network address access, and set its default route to the IP address owned by the Docker host on the bridge.
After these steps are completed, the container will immediately have an eth0 (virtual) network card and will find itself able to communicate with other containers as well as the Internet. You can use the option-net= to execute docker run to launch a container, which has the following optional parameters.
-the default option for net=bridge- is to connect the docker container as a bridge. -net=host- docker skips the separate network stack of the configuration container. -net=container:NAME_or_ID- tells docker to let the newly created container use the network configuration of the existing container. -net=none- tells docker to set up a network stack for the newly created container, but does not configure the network stack, so it can only access the local network, not the external network. One, bridging mode
This is the default network mode of docker, and the Docker daemon creates docker0, a virtual Ethernet bridge, that automatically forwards packets between any network interfaces connected to it. In bridge mode, containers connected to the same bridge can communicate with each other.
[root@sta2 docker] # docker run-it-P-- name mynginx nginx # port mapping for containers
When using bridge mode, docker creates a bridge for docker0 and adds this network device to the docker0 bridge, which can be viewed by the brctl show command.
[root@sta2 ~] # brctl showbridge name bridge id STP enabled interfacesdocker0 8000.3e2d35d38bae no vethab6aea2
Assign an IP from the docker0 subnet to the container and set the IP address of the docker0 as the default gateway of the container.
Network configuration in the container:
View the mapped port configuration:
[root@sta2 docker] # docker ps-l
Or use the following methods to view the mapped port configuration:
[root@sta2 docker] # docker port mynginx443/tcp-> 0.0.0.0:3277480/tcp-> 0.0.0.0 0.0.0.0:3277480/tcp 32775
When using the-P flag, Docker randomly maps a port of 49000 to 49900 to a network port open in the internal container, and the ports mapped by nginx are fixed at 32774 and 32775.
View the access log:
[root@sta2 docker] # docker logs-f mynginx
Use-p (lowercase) to specify the port to map, and only one container can be bound on a specified port, and the-p flag can be used multiple times to bind multiple ports. The supported formats are ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort.
You can use hostPort:containerPort to map all interface addresses:
# docker run-d-p 5000RV 5000-- name mydocker nginx
All addresses on all local interfaces are bound by default. You can use ip:hostPort:containerPort format to specify that the mapping uses a specific address, mapped to the specified port of the specified address.
# docker run-d-p 127.0.0.1 5000-- name mydocker nginx
Use ip::containerPort to bind any port of localhost to port 5000 of the container, and the local host automatically assigns a port. Map to any port at the specified address:
# docker run-d-p 127.0.0.1 Freera 5000-- name mydocker nginx
Iptables rules are generated when docker makes port mapping, and iptables rules before port mapping:
Iptables rules after port mapping:
Second, host mode
This mode uses the host's network
# docker run-it-- name feiyu-host-- net=host busybox sh III, other container mode
In this mode, share a network with other containers
# docker run-it-- name feiyu-con-- net=container:feiyu busybox sh IV, none mode
This mode can only access the local network, not the external network.
This is the end of the content of "how to configure docker Network". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.