Docker獨立IP及容器互聯

用xshell遠程連接docker容器(分別在centos6.6和7上演示)
pull一個centos6.6的鏡像
[root@xinglinglove /]# docker pull elain/centos6.6
Using default tag: latest
latest: Pulling from elain/centos6.6
90577c79babf: Pull complete
3ea59202e096: Pull complete
Digest: sha256:bc2f692daf4d8e5cd0c2cae0ff91853c599c2055e3917e2dcb9a9d1b7d568420
Status: Downloaded newer image for elain/centos6.6:latest
[root@xinglinglove /]#
[root@xinglinglove /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7-v1 latest c74ccf891cd7 30 minutes ago 193MB
elain/centos6.6 latest 79da28bc1201 6 months ago 350MB
[root@xinglinglove /]# docker run -itd elain/centos6.6 /bin/bash
ddbc7965cd0ac219132dcb1c823d060daab3f5d844d7f65e450fa0ae83e3160e
[root@xinglinglove /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ddbc7965cd0a elain/centos6.6 “/bin/bash” 6 seconds ago Up 3 seconds inspiring_torvalds
[root@xinglinglove /]# docker exec -it ddbc7965cd0a /bin/bash
查看容器的ip
[root@ddbc7965cd0a /]# ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:02
inet addr:172.17.0.2 Bcast:0.0.0.0 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:648 (648.0 b) TX bytes:0 (0.0 b)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
查看容器開放的端口(默認沒有開啓任何端口)
[root@ddbc7965cd0a /]# netstat -tlunp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
開啓22端口
[root@ddbc7965cd0a /]# service sshd start
Starting sshd: [ OK ]
[root@ddbc7965cd0a /]# netstat -tlunp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 48/sshd
tcp 0 0 :::22 :::* LISTEN 48/sshd
創建用戶,設置密碼
[root@ddbc7965cd0a /]# useradd yws
[root@ddbc7965cd0a /]# passwd yws
Changing password for user yws.
New password:
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
用xshell遠程連接容器
[root@xinglinglove ~]# ssh -l yws 172.17.0.2
[email protected]’s password:
Last login: Sat Jun 3 06:37:56 2017 from 172.17.0.1
[yws@ddbc7965cd0a ~]$
在centos7.2上演示
查看實驗環境
[root@xinglinglove ~]# cat /etc/centos-release
CentOS Linux release 7.2.1511 (Core)
[root@xinglinglove ~]#
(1)停止docker服務
[root@xinglinglove ~]# systemctl stop docker.service
[root@xinglinglove ~]# ps -aux |grep docker
root 14670 0.0 0.0 112660 964 pts/1 R+ 15:05 0:00 grep –color=auto docker
(2)刪除docker0網卡
[root@xinglinglove ~]# ip link set dev docker0 down
[root@xinglinglove ~]# brctl delbr docker0
[root@xinglinglove ~]# ifconfig
eno16777736: flags=4163

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章