The docker container configuration and the same network host

The docker container configuration and the same network host

Host ip: 192.168.43.39

Network Configuration

[root@CentOS7-39 network-scripts]# cat ifcfg-br0 
TYPE="Bridge"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="br0"
UUID="fc9c13c1-c71a-4dc5-a82f-056aef34ff77"
DEVICE="br0"
ONBOOT="yes"
IPADDR="192.168.43.39"
PREFIX="24"
GATEWAY="192.168.43.2"
DNS1="192.168.43.2"
IPV6_PRIVACY="no"
[root@CentOS7-39 network-scripts]# cat ifcfg-ens33 
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
#UUID="fc9c13c1-c71a-4dc5-a82f-056aef34ff77"
DEVICE="ens33"
ONBOOT="yes"
#IPADDR="192.168.43.39"
#PREFIX="24"
#GATEWAY="192.168.43.2"
#DNS1="192.168.43.2"
IPV6_PRIVACY="no"
BRIDGE=br0

Installation pipwork

git clone https://github.com/jpetazzo/pipework
cp pipework/pipework /usr/local/bin/

Open container

docker run -itd --net=none --name peng centos8 bash

Ip and gateway configuration

pipework br0 peng 192.168.43.100/[email protected]

View of ip container peng

Here Insert Picture Description

[root@1f9b8ca46f55 /]# yum install passwd openssh-server -y
[root@1f9b8ca46f55 /]# passwd  //给root设置密码

启动 sshd 服务失败
Here Insert Picture Description

docker rm -f peng
docker run -itd --net=none --name=peng --privileged -e “container=docker” centos8 /usr/sbin/init
docker exec -it peng bash
Here Insert Picture Description
[root@de4add735c8b /]# exit
[root@CentOS7-39 ~]# pipework br0 peng 192.168.43.100/[email protected]
[root@de4add735c8b /]# yum install passwd openssh-server -y
[root@de4add735c8b /]# systemctl start sshd
Here Insert Picture Description
Here Insert Picture Description

Peng remotely connected to the container in a host 192.168.43.39 ip is 192.168.43.100
Here Insert Picture Description

Published 103 original articles · won praise 6 · views 20000 +

Guess you like

Origin blog.csdn.net/studywinwin/article/details/104878255