docker-network management

1. Delete all containers created or started (choose one of the two)

	# 暂停所有运行中的容器
	docker container ls -q | xargs docker container stop

	# 删除所有的容器
	docker container ls -aq | xargs docker container rm

Two, network management

  • After turning docker secretly, three networks will be automatically created by default. We can use the following command to view these networks

  • docker network ls

  • default:

    					brige		桥接
    				
    					host		主机
    				
    					none 		不设置
    
1. Brige bridge network
  • Create a new container, use --network bridge by default, use bridge by default
(1 Principle of bridge network usage
  • docker sets the port mapping method for the bridge network to port mapping, which is implemented through iptables
(2 iptables mapping port
		docker run 
		-d -p 10001:80 		-p	ip:hostPort:containerPort	将容器的端口发布到主机端口上
		--name shiyanlou001
		 shiyanlou:1.0

						
(3 Disadvantages
  • In the default bridge network, each time the container is restarted, the IP address of the container will change, because for the default bridge network, it is not possible to specify the IP pool when starting the container.
2. Custom network (bridge or overlay)
(1 Create a network
		docker network create 网络名	docker会随机生成网络接口名,和子网


		docker network create 
		-d bridge 				-d类型
		--subnet=192.168.16.0/24 		子网 		
		--gateway=192.168.16.1 网络名		网关
(2 Delete network
	docker network rm 网络名
(3 dns resolution between docker containers
  • The DNS service embedded in docker supports the resolution of container names linked to the network. Containers on the same network can ping another container by the container name.
3. Host and none
  • host network, the container can directly access the network on the host

  • None network, no other network interfaces are provided in the container. After the container of the none network is created, you can connect to a network by yourself

    • docker nework connect bridge container name, you can add the container to the bridge network

Guess you like

Origin blog.csdn.net/weixin_43272542/article/details/114579686