pipework固定容器ip

pipework是个啥?自己搜索下就知道了。

操作系统64bit

root@zxl-server:~# cat /etc/issue
Ubuntu 14.04 LTS \n \l

下载pipework软件包以及解压

root@zxl-server:~# wget https://github.com/jpetazzo/pipework/archive/master.zip
root@zxl-server:~# unzip master.zip 
Archive:  master.zip
0633ba9dbce2d336e0f10c46819f3a9fa9c8077b
   creating: pipework-master/
 extracting: pipework-master/.gitignore  
  inflating: pipework-master/LICENSE  
  inflating: pipework-master/README.md  
  inflating: pipework-master/docker-compose.yml  
   creating: pipework-master/doctoc/
  inflating: pipework-master/doctoc/Dockerfile  
  inflating: pipework-master/pipework  
  inflating: pipework-master/pipework.spec  
root@zxl-server:~# cd pipework-master/
root@zxl-server:~/pipework-master# cp pipework /usr/local/bin/

运行容器,--net=none指的是不位容器设置网络

root@zxl-server:~# docker run -itd --name x4 --net=none ubuntu
97753071bf40a538fd5b9c3fbb2c4e631aa0b184244092e91eb32ed5ab7a8247

为容器名字为x4设置ip地址为0.22,172.17.42.1是网关

root@zxl-server:~# pipework docker0 x4 172.17.0.22/[email protected]

进入容器名字为x4

root@zxl-server:~# docker-enter x4

查看容器设置的ip地址

root@4990dcc3c5e2:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
10: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 0a:d0:18:01:1d:50 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.22/24 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::8d0:18ff:fe01:1d50/64 scope link 
       valid_lft forever preferred_lft forever

安装ssh服务,设置配置sshd_config允许root登陆并设置密码。然后重启服务即可

root@4990dcc3c5e2:~# apt-get install openssh-server -y
root@4990dcc3c5e2:~# /etc/init.d/ssh restart
 * Restarting OpenBSD Secure Shell server sshd                                                                           [ OK ]

宿主机登陆容器x4,ip为172.17.0.22

root@zxl-server:~# ssh [email protected]
[email protected]'s password: 
Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.13.0-24-generic x86_64)
 * Documentation:  https://help.ubuntu.com/
Last login: Mon May 16 11:07:18 2016 from 172.17.42.1

ok就先这样了。容器之间都是能通信的,宿主机也能ssh管理容器了。

你可能感兴趣的:(IP,容器,pipework)