0.11.1版本docker安装与使用
关于什么是docker,请参考http://baike.baidu.com/view/11854949.htm?fr=aladdin 我的服务器是ubuntu server 12.04,硬件是dell R420 一、安装 1、安装源 1 2 3 apt-keyadv--keyserverhkp: //keyserver .ubuntu.com:80--recv-keys36A1D7869245C8950F966E92D8576A8BA88D21E9 sh-c "echodebhttps://get.docker.io/ubuntudockermain>/etc/apt/sources.list.d/docker.list" apt-getupdate 2、安装docker 1 apt-get install lxc-docker 3、下载tar包并加入镜像里 一般下载镜像的时候,都是先docker search image_name,然后docker pullimage_name 但由于最近GFW屏蔽了网络,在现在的时候会出现以下错误,根本pull不了镜像。 1 2 Pullingrepositorycentos 2014 /05/19 13:35:11Gethttps: //cdn-registry-1 .docker.io /v1/repositories/library/centos/tags : read tcp162.159.253.251:443:connectiontimedout 所以为了解决此问题,我就从别的地方下载了打包好的tar(后边会解释然后自己打包的),然后使用docker load导入 先下载(有centos与ubuntu) 1 2 wgethttp: //docker .widuu.com /centos . tar wgethttp: //docker .widuu.com /ubuntu . tar 加入到镜像里 1 2 dockerload-icentos. tar dockerload-iubuntu. tar 查看镜像列表 1 2 3 4 5 6 root@ip-10-10-25-218:~ /docker/images #dockerload-icentos.tar root@ip-10-10-25-218:~ /docker/images #dockerload-iubuntu.tar root@ip-10-10-25-218:~ /docker/images #dockerimages REPOSITORYTAGIMAGEIDCREATEDVIRTUALSIZE <none><none>607347d2a9463monthsago300.2MB ubuntu /widuu latest963b9d0e10ba3monthsago155MB 给centos的改个名 1 2 3 4 5 root@ip-10-10-25-218:~ /docker/images #dockertag607centos:latest root@ip-10-10-25-218:~ /docker/images #dockerimages REPOSITORYTAGIMAGEIDCREATEDVIRTUALSIZE centoslatest607347d2a9463monthsago300.2MB ubuntu /widuu latest963b9d0e10ba3monthsago155MB 测试镜像是否可用 1 2 3 4 5 6 7 8 9 root@ip-10-10-25-218:~ /docker/images #dockerimages REPOSITORYTAGIMAGEIDCREATEDVIRTUALSIZE centoslatest607347d2a9463monthsago300.2MB ubuntu /widuu latest963b9d0e10ba3monthsago155MB root@ip-10-10-25-218:~ /docker/images #dockerruncentos/bin/echo"hello,i'mcentossystem" hello,i'mcentossystem root@ip-10-10-25-218:~ /docker/images #dockerrunubuntu/widuu/bin/echo"hello,i'mubuntusystem" hello,i'mubuntusystem root@ip-10-10-25-218:~ /docker/images # 使用交换模式 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 bash -4.1 #root@ip-10-10-25-218:~/docker/exercise/node#dockerrun-i-tcentos/bin/bash bash -4.1 #ifconfig eth0Linkencap:EthernetHWaddrBA:08:86:7F:F8:48 inetaddr:172.17.0.6Bcast:0.0.0.0Mask:255.255.0.0 inet6addr:fe80::b808:86ff:fe7f:f848 /64Scope :Link UPBROADCASTRUNNINGMTU:1500Metric:1 RXpackets:6errors:0dropped:2overruns:0frame:0 TXpackets:2errors:0dropped:0overruns:0carrier:0 collisions:0txqueuelen:1000 RXbytes:488(488.0b)TXbytes:168(168.0b) loLinkencap:LocalLoopback inetaddr:127.0.0.1Mask:255.0.0.0 inet6addr:::1 /128 Scope:Host UPLOOPBACKRUNNINGMTU:1500Metric:1 RXpackets:0errors:0dropped:0overruns:0frame:0 TXpackets:0errors:0dropped:0overruns:0carrier:0 collisions:0txqueuelen:0 RXbytes:0(0.0b)TXbytes:0(0.0b) bash -4.1 #exit 退出有2中一种是完全退出,使用exit,另外一中是不完全退出,使用ctrl-p与ctrl-q 这样你推人退出了,但容器状态还是存在。 可用使用docker attach CONTAINER ID来重新进入 二、私有库 由于GFW,所以玩docker没办法pull与push,并且为了安全考虑,为了解决就搭建了私有库。 1 2 3 4 5 6 7 8 9 10 gitclonehttps: //github .com /dotcloud/docker-registry .git cddocker-registry cd config cpconfig_sample.ymlconfig.yml cd .. apt-getinstallpython-pipgunicornbuild-essentialpython-devlibevent-dev python-pipliblzma-dev-y pipinstall-rrequirements.txt gunicorn-kgevent--max-requests100--graceful-timeout3600-t3600-blocalhost:5000-w8-D--access-logfile /tmp/gunicorn .logdocker_registry.wsgi:application 客户端推送镜像到私有库 1、先注册账号 1 dockerloginlocalhost:5000 依次输入你的账号、密码、email 2、给提交的镜像打标签 1 2 3 4 5 6 root@ip-10-10-25-218:~ /docker/exercise/node #dockerimages REPOSITORYTAGIMAGEIDCREATEDVIRTUALSIZE centos-initlatest5abf7cce37673minutesago1.034GB centoslatest607347d2a9463monthsago300.2MB ubuntu /widuu latest963b9d0e10ba3monthsago155MB root@ip-10-10-25-218:~ /docker/exercise/node #dockertag5abf7cce3767localhost:5000/centos-init 3、推送到私有库 1 2 3 4 5 6 7 8 9 10 11 12 13 14 root@ip-10-10-25-218:~ /docker/exercise/node #dockerpushlocalhost:5000/centos-init Thepushreferstoarepository[localhost:5000 /centos-init ](len:1) Sendingimagelist Pushingrepositorylocalhost:5000 /centos-init (1tags) Image384630bcda7calreadypushed,skipping Image607347d2a946alreadypushed,skipping 5abf7cce3767:Imagesuccessfullypushed Pushingtag for rev[5abf7cce3767]on{http: //localhost :5000 /v1/repositories/centos-init/tags/latest } root@ip-10-10-25-218:~ /docker/exercise/node #dockerimages REPOSITORYTAGIMAGEIDCREATEDVIRTUALSIZE centos-initlatest5abf7cce37676minutesago1.034GB localhost:5000 /centos-init latest5abf7cce37676minutesago1.034GB centoslatest607347d2a9463monthsago300.2MB ubuntu /widuu latest963b9d0e10ba3monthsago155MB 三、自制镜像 参考http://docs.docker.io/articles/baseimages/ 我是在ubuntu系统,所以使用https://github.com/dotcloud/docker/blob/master/contrib/mkimage-rinse.sh 由于使用rinse创建,所以需要安装 1 apt-get install rinse 安装centos 5系统 1 bash mkimage-rinse.shdenglei /centos centos-5 安装centos 6系统 检测 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 root@ip-10-10-25-218: /tmp #dockerimages REPOSITORYTAGIMAGEIDCREATEDVIRTUALSIZE denglei /centos 6.518eb9205a9272minutesago127.2MB denglei /centos 5.102b76af55f4cc5minutesago81.08MB centos-test2latest21639e6b708aAboutanhourago356.7MB ubuntu- test latesta95d7aa1d99139hoursago161.8MB centos- test latest28870be2e71639hoursago356.7MB centos-omsalatestd3c15db5624e39hoursago1.048GB centos-initlatest58ef41091c2b11daysago1.055GB localhost:5000 /centos-init latest5abf7cce376711daysago1.034GB centoslatest607347d2a9464monthsago300.2MB ubuntu /widuu latest963b9d0e10ba4monthsago155MB root@ip-10-10-25-218: /tmp #dockerrundenglei/centos:5.10/bin/echo"hello,i'mcentos5.10system" hello,i'mcentos5.10system root@ip-10-10-25-218: /tmp #dockerrundenglei/centos:6.5/bin/echo"hello,i'mcentos6.5system" hello,i'mcentos6.5system docker里centos无法ssh的问题 需要关闭pam 1 sed -i "s/UsePAM.*/UsePAMno/g" /etc/ssh/sshd_config 重启ssh服务 1 /etc/init .d /sshd restart 同时别忘记设置密码 本文转自 reinxu 51CTO博客,原文链接:http://blog.51cto.com/dl528888/1427150,如需转载请自行联系原作者