点击(此处)折叠或打开
- 创建公共(public)仓库:
- #将扩展的ubuntu:php镜像上传到https://hup.docker.com
- #需在https://hub.docker.com创建一个账号。
- #命令行上传
- #root@ubuntu:/docker# docker tag ubuntu:php sxm5211258/ubuntu:php
- root@ubuntu:/docker# docker login
- Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
- Username (account): account
- Password:
- Login Succeeded
- #account指的是hub.docker.com的账号
- root@ubuntu:/docker# docker push account/ubuntu:php
- The push refers to a repository [docker.io/account/ubuntu]
- 283340951aa2: Pushed
- ...
- 0f5ff0cf6a1c: Mounted from library/ubuntu
- 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)配置:
点击(此处)折叠或打开
- #创建本地私有(private)仓库:
- #运行一个本地registry,如果没有pull registry,执行run会自行下载registry。
- #***-v 指定路径的时候路径名结尾一定要加上/,否者push后指定的路径里面不会有image***
- root@ubuntu:/home/ubuntu# docker run -d -p 5000:5000 --restart=always --name registry -v /docker/registry/:/var/lib/registry/ registry:2
- 7fec8c18f47606419548bde55a16cf6b2bf0f760fba0e8021c279ebfec1edb56
- -d 放到后台运行
- -p 指定端口
- -e REGISTRY_HTTP_ADDR=0.0.0.0:5001 可以通过环境变量指定端口。
- 5000:5000 第一个5000是主机端口 第二个5000是容器内的端口。
- -v /docker/registry创建宿主机镜像文件存放仓库,默认创建在/var/registry
- --restart=always 在容器重启退出时重启,默认为no
- --name 为容器命名
- #下载一个ubuntu 镜像
- root@ubuntu:/home/ubuntu# docker pull ubuntu:16.04
- root@ubuntu:/home/ubuntu# docker tag ubuntu:16.04 192.168.3.59:5000/my-ubuntu
- root@ubuntu:/home/ubuntu# docker push 192.168.3.59:5000/my-ubuntu
- Get https://192.168.3.59:5000/v1/_ping: http: server gave HTTP response to HTTPS client
- docker push到本地镜像仓库提示的https错误,执行下列操作:
- root@ubuntu:/home/ubuntu# echo '{"insecure-registries":["192.168.3.59:5000"]}' > /etc/docker/daemon.json
- root@ubuntu:/home/ubuntu# systemctl restart docker
- root@ubuntu:/home/ubuntu# docker push 192.168.3.59:5000/my-ubuntu
- The push refers to a repository [192.168.3.59:5000/my-ubuntu]
- 174a611570d4: Pushed
- ...
- 0f5ff0cf6a1c: Pushed
- latest: digest: sha256:907d6603aa342ad193dfc6c9c3e906bf087043faf827bba893ea3762a798c8ef size: 1357
- #查看本地镜像库
- root@ubuntu:/docker/registry# tree
- .
- └── docker
- └── registry
- └── v2
- └── repositories
- └── my-debian
- └── _manifests
- ├── revisions
- │ └── sha256
- │ └── 409391651b06d0617e001d67d1e1936b6a14cec1be8bb39ba550cac42500d5f5
- │ └── link
- └── tags
- └── latest
- ├── current
- │ └── link
- └── index
- └── sha256
- └── 409391651b06d0617e001d67d1e1936b6a14cec1be8bb39ba550cac42500d5f5
- └── link
- 15 directories, 3 files
点击(此处)折叠或打开
- #去私有仓库拉取my-ubuntu镜像
- [root@localehost docker]# docker pull 192.168.3.59:5000/my-ubuntu
- 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/
- v2 ping attempt failed with error: Get https://192.168.3.59:5000/v2/: tls: oversized record received with length 20527
- 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
- #--insecure-registry 启用不安全的通信
- [root@localehost docker]# docker -d --insecure-registry 192.168.3.59:5000 &
- INFO[0000] [graphdriver] using prior storage driver "aufs"
- WARN[0000] Running modprobe bridge nf_nat failed with message: , error: exit status 1
- WARN[0000] Your kernel does not support swap memory limit.
- INFO[0000] Loading containers: start.
- ........
- INFO[0000] Loading containers: done.
- INFO[0000] Daemon has completed initialization
- INFO[0000] Docker daemon commit=786b29d/1.7.1 execdriver=native-0.2 graphdriver=aufs version=1.7.1
- 或
- #修改/etc/sysconfig/docker配置文件
- [root@localehost docker]# vim /etc/sysconfig/docker
- 修改
- other_args="--insecure-registry 192.168.3.59:5000"
- #在重新拉取私有仓库的镜像
- [root@localehost docker]# docker pull 192.168.3.59:5000/my-ubuntu
- INFO[0054] POST /v1.19/images/create?fromImage=192.168.3.59%3A5000%2Fmy-ubuntu%3Alatest
- latest: Pulling from 192.168.3.59:5000/my-ubuntu
- 5ea87f3c8f7e: Pull complete
- ...
- fbd045c51dd7: Pull complete
- Digest: sha256:f1f313a95997f65f147f080bac1e0126dcd56c07ac43bf72d8da70274f5c9247
- Status: Downloaded newer image for 192.168.3.59:5000/my-ubuntu:latest
- #查看本地images,可以看到已经拉取过来的my-ubuntu
- [root@localehost docker]# docker images
- INFO[0119] GET /v1.19/images/json
- 192.168.3.59:5000/my-ubuntu latest fbd045c51dd7 5 days ago 122 MB
- #将本地镜像busybox推送到私有仓库上面
- [root@localehost docker]# docker push 192.168.3.59:5000/busybox
- INFO[0138] POST /v1.19/images/192.168.3.59:5000/busybox/push?tag=
- The push refers to a repository [192.168.3.59:5000/busybox] (len: 1)
- 97d69bba9a9d: Image successfully pushed
- 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
- Digest: sha256:dd24d998c085d2574a33e1145c4865e0d8161b54ccbb5b31f310c2a0ba2d43f1