没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
docker 宿主机配置容器桥接网络并给容器部署桥接 IP 和启动 sshd 服务供外部远程连接
一、docker 宿主机配置容器桥接网络并给容器部署桥接 IP 和启动 sshd 服务供外部远程连接
说明: 原来宿主机 ip: 192.168.14.140 原来宿主机网关: 192.168.14.2 原来宿主机网卡名字:ens33
1.安装 centos7 系统:
刚安装完 centos7 时(nat 模式虚拟机)自动获取的 IP 是:192.168.140,自动分配的网关:192.168.14.2
[root@bogon ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.14.140 netmask 255.255.255.0 broadcast 192.168.14.255
inet6 fe80::29a3:566b:af9e:e0d5 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:14:3a:22 txqueuelen 1000 (Ethernet)
RX packets 407468 bytes 585262453 (558.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 124643 bytes 10172407 (9.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 4 bytes 340 (340.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4 bytes 340 (340.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2.安装 docker 服务并下载相关镜像(主要 cent6.5 且带 sshd 服务的):
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@localhost ~]# systemctl stop firewalld.service #关闭防火墙
[root@localhost ~]# systemctl disable firewalld.service #禁止防火墙开机自启
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce 0 #此处是否关闭 selinux 和下面报错没关系,尽量关闭吧
[root@localhost ~]# yum -y install docker #安装 docker
[root@localhost ~]# systemctl start docker #启动 docker,下面错误
Job for docker.service failed because the control process exited with error code. See "systemctl status
docker.service" and "journalctl -xe" for details.
#注意包上面错,是因为此 linux 的内核中的 SELinux 不支持 overlay2 graph driver,解决方法:要么启动一个新内核,要么
就在 docker 里禁用 selinux,--selinux-enabled=false
[root@localhost ~]# vi /etc/sysconfig/docker #前面是禁用 selinux,后面是为了能下载镜像
# /etc/sysconfig/docker
# Modify these options if you want to change the way the docker daemon runs
OPTIONS='--selinux-enabled=false --log-driver=journald --signature-verification=false --registry-mirror=http://f2d6cb40.m.daocloud.io' #添加该源
if [ -z "${DOCKER_CERT_PATH}" ]; then
DOCKER_CERT_PATH=/etc/docker
fi
……….
[root@localhost ~]# systemctl start docker #启动 docker 成功
[root@localhost ~]# ps -ef |grep docker
root 17892 1 0 13:27 ? 00:00:00 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current
--default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current
--seccomp-profile=/etc/docker/seccomp.json --selinux-enabled=false --log-driver=journald --signature-verification=false --storage-driver overlay2
root 17897 17892 0 13:27 ? 00:00:00 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock
--metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime docker-runc
--runtime-args --systemd-cgroup=true
root 17997 9842 0 13:28 pts/1 00:00:00 grep --color=auto docker
启动完 docker 后会增加一个 docker0 网卡和对应 IP
[root@bogon ~]# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
ether 02:42:ec:00:84:a2 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.14.140 netmask 255.255.255.0 broadcast 192.168.14.255
inet6 fe80::29a3:566b:af9e:e0d5 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:14:3a:22 txqueuelen 1000 (Ethernet)
RX packets 407468 bytes 585262453 (558.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 124643 bytes 10172407 (9.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 4 bytes 340 (340.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4 bytes 340 (340.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# systemctl stop docker #是停止 docker,说明一下就不停止了
[root@localhost ~]# docker --version
Docker version 1.13.1, build 774336d/1.13.1
[root@bogon ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@bogon ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
[root@bogon ~]# docker search centos 或 centso6 搜索镜像
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/imagine10255/centos6-lnmp-php56 centos6-lnmp-php56 46 [OK]
docker.io docker.io/lemonbar/centos6-ssh Installed openssh-server on centos6, defau... 14 [OK]
.......
[root@bogon ~]# docker pull docker.io/lemonbar/centos6-ssh #下载 cent6.5 的镜像且带 sshd 服务的
[root@bogon ~]# docker pull docker.io/centos #下载的镜像是 centos 最新的,一般是 cent7
[root@bogon ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
[root@bogon ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/centos latest 5182e96772bf 2 months ago 200 MB
docker.io/lemonbar/centos6-ssh latest efd998bd6817 4 years ago 297 MB
[root@bogon ~]# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:a1ff:fee7:9e89 prefixlen 64 scopeid 0x20<link>
ether 02:42:a1:e7:9e:89 txqueuelen 0 (Ethernet)
RX packets 19070 bytes 881798 (861.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 25439 bytes 67724466 (64.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.14.140 netmask 255.255.255.0 broadcast 192.168.14.255
inet6 fe80::29a3:566b:af9e:e0d5 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:14:3a:22 txqueuelen 1000 (Ethernet)
RX packets 402656 bytes 578472806 (551.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 121983 bytes 9987468 (9.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 4 bytes 340 (340.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4 bytes 340 (340.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
3.配置网络桥接,建立容器,并给容器部署桥接网络 ip:
1)停止 docker 服务:
剩余10页未读,继续阅读
资源评论
运维实战课程
- 粉丝: 1581
- 资源: 410
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功