Chinaunix首页 | 论坛 | 博客
  • 博客访问: 405162
  • 博文数量: 112
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 800
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-29 13:41
文章分类

全部博文(112)

文章存档

2020年(1)

2018年(10)

2017年(27)

2016年(18)

2015年(31)

2014年(25)

分类: 虚拟化

2017-11-03 16:37:51

一、搭建公有仓库:

点击(此处)折叠或打开

  1. 创建公共(public)仓库:
  2. #将扩展的ubuntu:php镜像上传到https://hup.docker.com
  3. #需在https://hub.docker.com创建一个账号。
  4. #命令行上传
  5. #root@ubuntu:/docker# docker tag ubuntu:php sxm5211258/ubuntu:php
  6. root@ubuntu:/docker# docker login
  7. Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to to create one.
  8. Username (account): account
  9. Password:
  10. Login Succeeded
  11. #account指的是hub.docker.com的账号
  12. root@ubuntu:/docker# docker push account/ubuntu:php
  13. The push refers to a repository [docker.io/account/ubuntu]
  14. 283340951aa2: Pushed
  15. ...
  16. 0f5ff0cf6a1c: Mounted from library/ubuntu
  17. php: digest: sha256:c9ddd4636c061faf1b1ea4f4b0bcfb0bcb9d41bbd5eb36e51519d63709862c76 size: 1781

二、搭建私有仓库
docker私有仓库宿主机:
OS:ubuntu xenial 16.04.1 x86_64
KERNEL:4.4.0-98-generic
IP:192.168.3.59  

客户机主机:
OS:CentOS release 6.5  x86_64
KERNEL:3.10.5-3.el6.x86_64
IP:192.168.3.60

1、Docker私有仓库宿主机(ubuntu16.04)配置:

点击(此处)折叠或打开

  1. #创建本地私有(private)仓库:
  2. #运行一个本地registry,如果没有pull registry,执行run会自行下载registry。
  3. #***-v 指定路径的时候路径名结尾一定要加上/,否者push后指定的路径里面不会有image***
  4. root@ubuntu:/home/ubuntu# docker run -d -p 5000:5000 --restart=always --name registry -v /docker/registry/:/var/lib/registry/ registry:2
  5. 7fec8c18f47606419548bde55a16cf6b2bf0f760fba0e8021c279ebfec1edb56
  6. -d 放到后台运行
  7. -p 指定端口
  8. -e REGISTRY_HTTP_ADDR=0.0.0.0:5001 可以通过环境变量指定端口。
  9. 5000:5000 第一个5000是主机端口 第二个5000是容器内的端口。
  10. -v /docker/registry创建宿主机镜像文件存放仓库,默认创建在/var/registry
  11. --restart=always 在容器重启退出时重启,默认为no
  12. --name 为容器命名
  13. #下载一个ubuntu 镜像
  14. root@ubuntu:/home/ubuntu# docker pull ubuntu:16.04
  15. root@ubuntu:/home/ubuntu# docker tag ubuntu:16.04 192.168.3.59:5000/my-ubuntu
  16. root@ubuntu:/home/ubuntu# docker push 192.168.3.59:5000/my-ubuntu
  17. Get https://192.168.3.59:5000/v1/_ping: http: server gave HTTP response to HTTPS client
  18. docker push到本地镜像仓库提示的https错误,执行下列操作:
  19. root@ubuntu:/home/ubuntu# echo '{"insecure-registries":["192.168.3.59:5000"]}' > /etc/docker/daemon.json
  20. root@ubuntu:/home/ubuntu# systemctl restart docker
  21. root@ubuntu:/home/ubuntu# docker push 192.168.3.59:5000/my-ubuntu
  22. The push refers to a repository [192.168.3.59:5000/my-ubuntu]
  23. 174a611570d4: Pushed
  24. ...
  25. 0f5ff0cf6a1c: Pushed
  26. latest: digest: sha256:907d6603aa342ad193dfc6c9c3e906bf087043faf827bba893ea3762a798c8ef size: 1357
  27. #查看本地镜像库
  28. root@ubuntu:/docker/registry# tree
  29. .
  30. └── docker
  31.     └── registry
  32.         └── v2
  33.             └── repositories
  34.                 └── my-debian
  35.                     └── _manifests
  36.                         ├── revisions
  37.                         │   └── sha256
  38.                         │   └── 409391651b06d0617e001d67d1e1936b6a14cec1be8bb39ba550cac42500d5f5
  39.                         │   └── link
  40.                         └── tags
  41.                             └── latest
  42.                                 ├── current
  43.                                 │   └── link
  44.                                 └── index
  45.                                     └── sha256
  46.                                         └── 409391651b06d0617e001d67d1e1936b6a14cec1be8bb39ba550cac42500d5f5
  47.                                             └── link

  48. 15 directories, 3 files

2、客户机(CentOS6.5)配置:

点击(此处)折叠或打开

  1. #去私有仓库拉取my-ubuntu镜像
  2. [root@localehost docker]# docker pull 192.168.3.59:5000/my-ubuntu
  3. Error response from daemon: invalid registry endpoint https://192.168.3.59:5000/v0/: unable to ping registry endpoint https://192.168.3.59:5000/v0/
  4. v2 ping attempt failed with error: Get https://192.168.3.59:5000/v2/: tls: oversized record received with length 20527
  5.  v1 ping attempt failed with error: Get https://192.168.3.59:5000/v1/_ping: tls: oversized record received with length 20527. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry 192.168.3.59:5000` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/192.168.3.59:5000/ca.crt
  6. #--insecure-registry 启用不安全的通信
  7. [root@localehost docker]# docker -d --insecure-registry 192.168.3.59:5000 &
  8. INFO[0000] [graphdriver] using prior storage driver "aufs"
  9. WARN[0000] Running modprobe bridge nf_nat failed with message: , error: exit status 1
  10. WARN[0000] Your kernel does not support swap memory limit.
  11. INFO[0000] Loading containers: start.
  12. ........
  13. INFO[0000] Loading containers: done.
  14. INFO[0000] Daemon has completed initialization 
  15. INFO[0000] Docker daemon                                 commit=786b29d/1.7.1 execdriver=native-0.2 graphdriver=aufs version=1.7.1
  16. #修改/etc/sysconfig/docker配置文件
  17. [root@localehost docker]# vim /etc/sysconfig/docker
  18. 修改
  19. other_args="--insecure-registry 192.168.3.59:5000"
  20. #在重新拉取私有仓库的镜像
  21. [root@localehost docker]# docker pull 192.168.3.59:5000/my-ubuntu
  22. INFO[0054] POST /v1.19/images/create?fromImage=192.168.3.59%3A5000%2Fmy-ubuntu%3Alatest
  23. latest: Pulling from 192.168.3.59:5000/my-ubuntu
  24. 5ea87f3c8f7e: Pull complete
  25. ...
  26. fbd045c51dd7: Pull complete 
  27. Digest: sha256:f1f313a95997f65f147f080bac1e0126dcd56c07ac43bf72d8da70274f5c9247
  28. Status: Downloaded newer image for 192.168.3.59:5000/my-ubuntu:latest
  29. #查看本地images,可以看到已经拉取过来的my-ubuntu
  30. [root@localehost docker]# docker images
  31. INFO[0119] GET /v1.19/images/json
  32. 192.168.3.59:5000/my-ubuntu   latest              fbd045c51dd7        5 days ago          122 MB
  33. #将本地镜像busybox推送到私有仓库上面
  34. [root@localehost docker]# docker push 192.168.3.59:5000/busybox
  35. INFO[0138] POST /v1.19/images/192.168.3.59:5000/busybox/push?tag=
  36. The push refers to a repository [192.168.3.59:5000/busybox] (len: 1)
  37. 97d69bba9a9d: Image successfully pushed
  38. INFO[0138] Signed manifest for 192.168.3.59:5000/busybox:latest using daemon's key: BO5L:TZKP:ZXR4:3R7J:OJFF:2DS3:URKQ:GXWP:EBBU:BRCS:DK67:7CZ5
  39. Digest: sha256:dd24d998c085d2574a33e1145c4865e0d8161b54ccbb5b31f310c2a0ba2d43f1






阅读(3507) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~