设为首页 收藏本站
查看: 1094|回复: 0

[经验分享] 0.11.1版本docker安装与使用

[复制链接]

尚未签到

发表于 2018-5-30 11:01:31 | 显示全部楼层 |阅读模式
  关于什么是docker,请参考http://baike.baidu.com/view/11854949.htm?fr=aladdin
  我的服务器是ubuntu server 12.04,硬件是dell R420
  一、安装

  1、安装源

apt-keyadv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys36A1D7869245C8950F966E92D8576A8BA88D21E9
sh -c"echo deb https://get.docker.io/ubuntu docker main>/etc/apt/sources.list.d/docker.list"
apt-getupdate  2、安装docker

apt-get install lxc-docker  3、下载tar包并加入镜像里
  一般下载镜像的时候,都是先docker search image_name,然后docker pullimage_name
但由于最近GFW屏蔽了网络,在现在的时候会出现以下错误,根本pull不了镜像。
  
Pullingrepository centos
2014/05/19 13:35:11 Gethttps://cdn-registry-1.docker.io/v1/repositories/library/centos/tags: read tcp162.159.253.251:443: connection timed out  所以为了解决此问题,我就从别的地方下载了打包好的tar(后边会解释然后自己打包的),然后使用docker load导入
  先下载(有centos与ubuntu)
wget http://docker.widuu.com/centos.tar
wget http://docker.widuu.com/ubuntu.tar  加入到镜像里
docker load -i centos.tar
docker load -i ubuntu.tar  查看镜像列表
root@ip-10-10-25-218:~/docker/images#docker load -i centos.tar
root@ip-10-10-25-218:~/docker/images#docker load -i ubuntu.tar
root@ip-10-10-25-218:~/docker/images#docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
<none>              <none>              607347d2a946        3 months ago        300.2 MB
ubuntu/widuu       latest             963b9d0e10ba        3 monthsago        155 MB  给centos的改个名
root@ip-10-10-25-218:~/docker/images#docker tag 607 centos:latest
root@ip-10-10-25-218:~/docker/images#docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              latest              607347d2a946        3 months ago        300.2 MB
ubuntu/widuu       latest             963b9d0e10ba        3 monthsago        155 MB测试镜像是否可用
  
root@ip-10-10-25-218:~/docker/images#docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              latest              607347d2a946        3 months ago        300.2 MB
ubuntu/widuu        latest              963b9d0e10ba        3 months ago        155 MB
root@ip-10-10-25-218:~/docker/images#docker run centos /bin/echo "hello,i'm centos system"
hello,i'mcentos system
root@ip-10-10-25-218:~/docker/images#docker run ubuntu/widuu /bin/echo "hello,i'm ubuntu system"
hello,i'mubuntu system
root@ip-10-10-25-218:~/docker/images#  使用交换模式
bash-4.1#root@ip-10-10-25-218:~/docker/exercise/node# docker run -i -t centos /bin/bash
bash-4.1#ifconfig
eth0      Link encap:Ethernet  HWaddr BA:08:86:7F:F8:48
          inet addr:172.17.0.6  Bcast:0.0.0.0 Mask:255.255.0.0
          inet6 addr: fe80::b808:86ff:fe7f:f848/64Scope:Link
          UP BROADCAST RUNNING  MTU:1500 Metric:1
          RX packets:6 errors:0 dropped:2overruns:0 frame:0
          TX packets:2 errors:0 dropped:0overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:488 (488.0 b)  TX bytes:168 (168.0 b)
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:1500 Metric:1
          RX packets:0 errors:0 dropped:0overruns:0 frame:0
          TX packets:0 errors:0 dropped:0overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
bash-4.1# exit退出有2中一种是完全退出,使用exit,另外一中是不完全退出,使用ctrl-p与ctrl-q
  这样你推人退出了,但容器状态还是存在。
可用使用docker attach CONTAINER ID来重新进入
  二、私有库
  由于GFW,所以玩docker没办法pull与push,并且为了安全考虑,为了解决就搭建了私有库。
git clonehttps://github.com/dotcloud/docker-registry.git
cddocker-registry
cd config
cpconfig_sample.yml config.yml
cd ..
apt-getinstall python-pip gunicorn build-essential python-dev libevent-dev
python-pipliblzma-dev -y
pipinstall -r requirements.txt
gunicorn-k gevent --max-requests 100 --graceful-timeout 3600 -t 3600 -b localhost:5000-w 8 -D  --access-logfile /tmp/gunicorn.log  docker_registry.wsgi:application  客户端推送镜像到私有库
  1、  先注册账号
docker login localhost:5000  依次输入你的账号、密码、email
  2、给提交的镜像打标签
root@ip-10-10-25-218:~/docker/exercise/node#docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos-init         latest              5abf7cce3767        3 minutes ago       1.034 GB
centos              latest              607347d2a946        3 months ago        300.2 MB
ubuntu/widuu        latest              963b9d0e10ba        3 months ago        155 MB
root@ip-10-10-25-218:~/docker/exercise/node# docker tag5abf7cce3767 localhost:5000/centos-init  3、推送到私有库
root@ip-10-10-25-218:~/docker/exercise/node#docker push localhost:5000/centos-init
The pushrefers to a repository [localhost:5000/centos-init] (len: 1)
Sendingimage list
Pushingrepository localhost:5000/centos-init (1 tags)
Image384630bcda7c already pushed, skipping
Image607347d2a946 already pushed, skipping
5abf7cce3767:Image successfully pushed
Pushingtag for rev [5abf7cce3767] on{http://localhost:5000/v1/repositories/centos-init/tags/latest}
root@ip-10-10-25-218:~/docker/exercise/node#docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos-init                  latest              5abf7cce3767        6 minutes ago       1.034 GB
localhost:5000/centos-init   latest              5abf7cce3767        6 minutes ago       1.034 GB
centos                       latest              607347d2a946        3 months ago        300.2 MB
ubuntu/widuu                latest             963b9d0e10ba        3 monthsago        155 MB  三、自制镜像
参考http://docs.docker.io/articles/baseimages/
我是在ubuntu系统,所以使用https://github.com/dotcloud/docker/blob/master/contrib/mkimage-rinse.sh
由于使用rinse创建,所以需要安装
apt-get install rinse  安装centos 5系统
bash mkimage-rinse.sh denglei/centos centos-5安装centos 6系统
  检测
root@ip-10-10-25-218:/tmp#docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
denglei/centos               6.5                 18eb9205a927        2 minutes ago       127.2 MB
denglei/centos               5.10                2b76af55f4cc        5 minutes ago       81.08 MB
centos-test2                 latest              21639e6b708a        About an hour ago   356.7 MB
ubuntu-test                  latest              a95d7aa1d991        39 hours ago        161.8 MB
centos-test                  latest              28870be2e716        39 hours ago        356.7 MB
centos-omsa                  latest              d3c15db5624e        39 hours ago        1.048 GB
centos-init                  latest              58ef41091c2b        11 days ago         1.055 GB
localhost:5000/centos-init   latest              5abf7cce3767        11 days ago         1.034 GB
centos                       latest              607347d2a946        4 months ago        300.2 MB
ubuntu/widuu                latest             963b9d0e10ba        4 monthsago        155 MB
root@ip-10-10-25-218:/tmp#docker run denglei/centos:5.10 /bin/echo "hello,i'm centos 5.10system"
hello,i'mcentos 5.10 system
root@ip-10-10-25-218:/tmp#docker run denglei/centos:6.5 /bin/echo "hello,i'm centos 6.5 system"
hello,i'm centos 6.5 system  docker里centos无法ssh的问题
  需要关闭pam
sed -i "s/UsePAM.*/UsePAMno/g" /etc/ssh/sshd_config  重启ssh服务

/etc/init.d/sshd restart  同时别忘记设置密码
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-483007-1-1.html 上篇帖子: Docker逻辑数据流 下篇帖子: Docker来势汹汹
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表