docker创建容器时默认采用bridge网络,自行分配ip,不允许自己指定;
在实际部署中,我们需要指定容器ip,不允许其自行分配ip,尤其是搭建集群时,固定ip是必须的。
查看网络模式,docker network ls
我们可以创建自己的bridge网络:yinong;创建容器的时候指定网络为yinong并指定ip即可;
创建一个新的bridge网络;
docker network create --driver bridge --subnet=171.17.12.0/16 --gateway=171.17.1.1 yinong
查看yinong网络信息
docker network inspect yinong
需要使用特权模式运行容器,不然容器中启动服务报错(如下图);可参考:https://blog.csdn.net/zhenliang8/article/details/78330658
镜像相当于可读的文本,容器是可以读写的文本;假如你在某镜像centos7运行的容器下,安装ifconfig,再次使用该镜像运行容器(如,容器id为b),则容器b下午ifconfig;
创建容器并指定容器ip;运行容器;
centos7下未安装ifconfig命令,可通过yum进行安装;yum install -y net-tools
安装ssh服务
yum install -y openssh-server
yum install -y openssh-clients
systemctl start sshd.service