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

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

[复制链接]

尚未签到

发表于 2018-5-30 08:05:07 | 显示全部楼层 |阅读模式
  服务器是ubuntu server 14.04,内核:3.13.0-32-generic  ,  硬件是dell R520
  一、安装

  方法一:

  通过系统自带包安装
  Ubuntu 14.04 版本系统中已经自带了 Docker 包,可以直接安装。
  $ sudo apt-get update
  $ sudo apt-get install -y docker.io
  $ sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker
  $ sudo sed -i '$acomplete -F _docker docker' /etc/bash_completion.d/docker.io
  

  方法二:
  通过Docker源安装最新版本
  要想安装最新版本的Docker需要使用Docker源来安装
  # apt-get -y install apt-transport-https
  # apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
  # bash -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
  # apt-get update
  # apt-get -y install lxc-docker
  # docker -v   //查看docker版本
  # ps -ef | grep docker
  root     17311     1  0 Feb13 ?        00:00:43 /usr/bin/docker -d
  

  2、下载tar包并加入镜像里
  一般下载镜像的时候,都是先docker search image_name,然后docker pull image_name
但由于最近GFW屏蔽了网络,在现在的时候会出现以下错误,根本pull不了镜像。

Pull ingrepository 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/ubuntu.tar

  
  wget http://docker.widuu.com/centos.tar

  加入到镜像里
#docker load -i centos.tar
#docker load -i ubuntu.tar
  查看镜像列表
  #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的改个名
  #docker tag 607 centos:latest
#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
  测试镜像是否可用
  #docker run centos /bin/echo "hello,i'm centos system"
hello,i'mcentos system
#docker run ubuntu/widuu /bin/echo "hello,i'm ubuntu system"
hello,i'mubuntu system
  使用交换模式
  #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.4  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来重新进入。
  如果你是完全退出了,docker容器状态显示Exited,需要重新启动docker容器,在使用attach进入.
  docker start CONTAINER ID
  docker attach CONTAINER ID
  

  在宿主机ubuntu上面测试使用ssh进行连接docker容器
  # 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.4  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)
  为docker容器里面root修改密码
  bash-4.1# passwd root
  New password:
/usr/share/cracklib/pw_dict.pwd: No such file or directory
PWOpen: No such file or directory
  解决方法:
  bash-4.1# rpm -e cracklib-dicts --nodeps
bash-4.1# rpm -e pam --nodeps
  bash-4.1# yum -y install cracklib-dicts pam
  bash-4.1# passwd root 就可以成功了。
  bash-4.1# service sshd start
  Starting sshd:                                             [  OK  ]
bash-4.1# netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN      
  在docker容器上面上面进行ssh连接报下面错误

  # ssh -l root 172.17.0.4
The authenticity of host '172.17.0.4 (172.17.0.4)' can't be established.
RSA key fingerprint is 9f:10:e8:9e:7c:a3:45:4e:ef:d0:19:f0:11:46:43:4e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.17.0.4' (RSA) to the list of known hosts.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

  解决方法:
  bash-4.1# vim /etc/ssh/sshd_config
  将PermitRootLogin no  改成 PermitRootLogin yes
  RSAAuthentication yes
  PubkeyAuthentication yes
  AuthorizedKeysFile     .ssh/authorized_keys

  bash-4.1#service sshd restart
  bash-4.1#setenforce 0

  bash-4.1# ssh -l root 172.17.0.4
  Last login: Fri Jun 26 07:09:47 2015 from 172.17.0.4
[root@504d16302ad4 ~]#
  发现登录成功。

  

  

  二、私有库

  由于GFW,所以玩docker没办法pull与push,并且为了安全考虑,为了解决就搭建了私有库。
  Docker 官方提供了 docker registry 的构建方法:https://github.com/docker/docker-registry
  

  方法一,快速构建
  快速构建 docker registry 通过以下两步:

  •   安装 docker
  •   运行 registry: docker run -p 5000:5000 registry
  这种方法通过 Docker hub 使用官方镜像 https://registry.hub.docker.com/_/registry/
  

  方法二,不使用容器构建registry

  
安装必要的软件
# apt-get install build-essential python-dev libevent-dev python-pip liblzma-dev gunicorn  python-dev -y配置 docker-registry
# pip install docker-registry或者 使用 github clone 手动安装
$ git clone https://github.com/dotcloud/docker-registry.git
$ cd docker-registry/
$ cp config/config_sample.yml config/config.yml
$ mkdir /data/registry -p
$ pip install .运行
# 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、给提交的镜像打标签
# docker ps
CONTAINER ID        IMAGE                COMMAND             CREATED             STATUS              PORTS               NAMES
504d16302ad4      
jdeathe/centos-ssh   "/bin/bash"         About an hour ago   Up 42
minutes       22/tcp              serene_bardeen  
# docker commit 504d16302ad4 centos:v1
b47276971c2db84bd76659da86a4ea5bda227f008c5004152232183066f20533
# docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos               v1                  b47276971c2d        7 seconds ago       376.8 MB
jdeathe/centos-ssh   latest              b071db8f6e23        4 weeks ago         238 MB
  3、推送到私有库
  # docker push localhost:5000/centos
The pushrefers to a repository [localhost:5000/centos] (len: 1)
Sendingimage list
Pushingrepository localhost:5000/centos (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/tags/latest}
  

  # docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos                  v1                  b47276971c2d        About an hour ago   376.8 MB
localhost:5000/centos   latest              b47276971c2d        About an hour ago   376.8 MB
jdeathe/centos-ssh      latest              b071db8f6e23        4 weeks ago         238 MB

  


  http://docker.widuu.com/
  http://aresy.blog.51cto.com/5100031/1553624

运维网声明 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-482814-1-1.html 上篇帖子: docker对镜像的相关操作 下篇帖子: 什么是Docker? 为什么要用Docker?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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