Host Network Sharing Mode
In the host network sharing mode, containers can directly use the network stack of the host. In Docker, the creation of an Nginx container that utilizes the host network sharing mode has implemented efficient communication between the container and the host network.
In CentOS or openEuler, to create and run a container connected to the Docker host network stack, perform the following steps:
- Create a container.
- CentOS:
1docker run -itd --privileged -v /home/share/:/home/share/ --cpuset-cpus 0-1 --cpuset-mems 0 --memory 8589934592 --net=host --name nginx_1 arm/centos7/nginx:http /bin/bash
- openEuler:
1docker run -itd --privileged -v /home/share/:/home/share/ --cpuset-cpus 0-1 --cpuset-mems 0 --memory 8589934592 --net=host --name nginx_1 arm/openeuler20/nginx:http /bin/bash
For details about the command description, see Table 1.
Table 1 Command description Command
Description
-v
Specifies a shared directory.
--cpuset-cpus
Specifies the physical cores allocated to the container.
--cpuset-mems
Specifies the node where the container memory is allocated.
--memory
Specifies the memory size allocated to the container.
--net
Specifies the network mode used by the container. In this example, the host network mode is used.
--name
Specifies the container name.
arm/centos7/nginx:http
Or
arm/openeuler20/nginx:http
Specifies the image used by the container.
You can use a script file to create containers in batches. The following is an example script that can create 24 containers in CentOS:
#!/bin/bash # filename: ContainerCreate.sh beginCore=0; endCore=1; for i in {1..6} do name=nginx_$i docker run -itd --privileged -v /home/share/:/home/share/ --cpuset-cpus $beginCore-$endCore --cpuset-mems 0 --memory 8589934592 --net=host --name $name arm/centos7/nginx:http /bin/bash let "beginCore+=4" let "endCore+=4" done for i in {7..12} do name=nginx_$i docker run -itd --privileged -v /home/share/:/home/share/ --cpuset-cpus $beginCore-$endCore --cpuset-mems 1 --memory 8589934592 --net=host --name $name arm/centos7/nginx:http /bin/bash let "beginCore+=4" let "endCore+=4" done for i in {13..18} do name=nginx_$i docker run -itd --privileged -v /home/share/:/home/share/ --cpuset-cpus $beginCore-$endCore --cpuset-mems 2 --memory 8589934592 --net=host --name $name arm/centos7/nginx:http /bin/bash let "beginCore+=4" let "endCore+=4" done for i in {19..24} do name=nginx_$i docker run -itd --privileged -v /home/share/:/home/share/ --cpuset-cpus $beginCore-$endCore --cpuset-mems 3 --memory 8589934592 --net=host --name $name arm/centos7/nginx:http /bin/bash let "beginCore+=4" let "endCore+=4" done - CentOS:
- Check the started containers.
1docker ps
If no container is displayed after you run the docker ps command, run the following command to view the error information:
1 2
docker ps -a docker logs nginx_1