When Docker creates a container, it uses the bridge network by default, assigning its own IP and not allowing itself to be specified.
In the actual deployment, we need to specify the container IP, not allow its own IP, especially when building a cluster, fixed IP is required.
We can create our own bridge network: MyNet, when you create a container, specify the network as MyNet and specify the IP.
View Network mode
Docker Network LS
Create a new bridge network
Docker Network create--driver bridge--SUBNET=172.18.12.0/16--gateway=172.18.1.1 mynet
View network Information
Docker Network Inspect MyNet
Create a container and specify the container IP
Docker run-e tz= "Asia/shanghai"--privileged-itd-h hadoop01.com--name hadoop01--network=mynet--ip 172.18.12.1 CentOS /usr/sbin/init
Running the container
Docker exec-it Hadoop01/bin/bash
CentOS minimized installation without Ifconfig command, can be installed via Yum
Yum Install-y Net-tools
Installing the SSH Service
Yum Install-y openssh-server
Yum Install-y openssh-clients
Systemctl Start Sshd.service
New non-root user
Useradd Brock
passwd Brock
Through local client access (specify a port or configure a standalone IP by creating a container)
Docker run-e tz= "Asia/shanghai"-P 6001:22--privileged-itd-h hadoop01.com--name hadoop01--network=mynet--ip 172.18. 12.1 Centos/usr/sbin/init
Or
Route-p add 172.18.12.0 MASK 255.255.255.0 10.0.75.2
Specify container IP when Docker creates container