docker_practice/repository/registry.md

120 lines
4.3 KiB
Go
Raw Normal View History

#
2017-11-22 20:28:10 +08:00
使 Docker Hub 便使
使
2017-11-30 16:59:04 +08:00
[`docker-registry`](https://docs.docker.com/registry/) 是官方提供的工具,可以用于构建私有的镜像仓库。本文内容基于 [`docker-registry`](https://github.com/docker/distribution) v2.x 版本。
2017-11-22 20:28:10 +08:00
## docker-registry
2017-11-22 20:28:10 +08:00
###
2017-11-22 20:28:10 +08:00
`registry`
```bash
$ docker run -d -p 5000:5000 --restart=always --name registry registry
```
2017-11-30 16:59:04 +08:00
使 `registry` `/var/lib/registry` `-v` `/opt/data/registry`
2017-11-22 20:28:10 +08:00
```bash
$ docker run -d \
-p 5000:5000 \
-v /opt/data/registry:/var/lib/registry \
registry
```
##
2017-11-22 20:28:10 +08:00
使 `docker tag` `127.0.0.1:5000`
```bash
2017-12-05 11:15:24 +08:00
$ docker image ls
2017-11-22 20:28:10 +08:00
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu latest ba5877dc9bec 6 weeks ago 192.7 MB
```
2017-12-05 11:15:24 +08:00
使 `docker tag` `ubuntu:latest` `127.0.0.1:5000/ubuntu:latest`
`docker tag IMAGE[:TAG] [REGISTRY_HOST[:REGISTRY_PORT]/]REPOSITORY[:TAG]`
2017-11-22 20:28:10 +08:00
```bash
$ docker tag ubuntu:latest 127.0.0.1:5000/ubuntu:latest
2017-12-05 11:15:24 +08:00
$ docker image ls
2017-11-22 20:28:10 +08:00
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu latest ba5877dc9bec 6 weeks ago 192.7 MB
127.0.0.1:5000/ubuntu:latest latest ba5877dc9bec 6 weeks ago 192.7 MB
```
使 `docker push`
```bash
$ docker push 127.0.0.1:5000/ubuntu:latest
The push refers to repository [127.0.0.1:5000/ubuntu]
373a30c24545: Pushed
a9148f5200b0: Pushed
cdd3de0940ab: Pushed
fc56279bbb33: Pushed
b38367233d37: Pushed
2aebd096e0e2: Pushed
latest: digest: sha256:fe4277621f10b5026266932ddf760f5a756d2facd505a94d2da12f4f52f71f5a size: 1568
```
`curl`
```bash
$ curl 127.0.0.1:5000/v2/_catalog
{"repositories":["ubuntu"]}
```
`{"repositories":["ubuntu"]}`
2017-11-30 16:59:04 +08:00
2017-11-22 20:28:10 +08:00
```bash
2017-12-05 11:15:24 +08:00
$ docker image rm 127.0.0.1:5000/ubuntu:latest
2017-11-22 20:28:10 +08:00
$ docker pull 127.0.0.1:5000/ubuntu:latest
Pulling repository 127.0.0.1:5000/ubuntu:latest
ba5877dc9bec: Download complete
511136ea3c5a: Download complete
9bad880da3d2: Download complete
25f11f5fb0cb: Download complete
ebc34468f71d: Download complete
2318d26665ef: Download complete
2017-12-05 11:15:24 +08:00
$ docker image ls
2017-11-22 20:28:10 +08:00
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
127.0.0.1:5000/ubuntu:latest latest ba5877dc9bec 6 weeks ago 192.7 MB
```
2017-11-30 16:59:04 +08:00
##
2017-11-30 16:59:04 +08:00
使 `127.0.0.1:5000` `192.168.199.100:5000`
2017-12-20 23:46:46 +08:00
Docker `HTTPS` Docker `HTTPS` 访
2017-11-30 16:59:04 +08:00
### Ubuntu 16.04+, Debian 8+, centos 7
2017-11-30 16:59:04 +08:00
使 `systemd` `/etc/docker/daemon.json`
```json
{
2017-12-01 15:46:26 +08:00
"registry-mirror": [
"https://dockerhub.azk8s.cn"
2017-12-01 15:46:26 +08:00
],
2017-11-30 16:59:04 +08:00
"insecure-registries": [
"192.168.199.100:5000"
]
}
```
2017-12-20 23:46:46 +08:00
> `json` Docker
##
2017-11-30 16:59:04 +08:00
Docker Desktop for Windows Docker Desktop for Mac `Docker Engine`