docker部署带配置的镜像(搭建Docker本地镜像私有仓库)
docker部署带配置的镜像(搭建Docker本地镜像私有仓库)curl http://192.168.146.134:5000/v2/_catalogroot@ubuntu:/# root@ubuntu:/# docker run -id --name zmf_registry -p 5000:5000 -v /export/registry:/var/lib/registry registry:2.7.1 ee6b52ae99f1a93bf7fbfa719685e72619a19e6b78d52ee068fdfd326f02bba5 root@ubuntu:/# root@ubuntu:/# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
1、根据注册服务镜像 registry 创建注册服务容器;
1)注册服务镜像 registry 的 dockerfile 文件;
# Build a minimal distribution container
FROM alpine:3.11
RUN set -ex \
&& apk add --no-cache ca-certificates
COPY ./registry /bin/registry
COPY ./config-example.yml /etc/docker/registry/config.yml
VOLUME ["/var/lib/registry"]
EXPOSE 5000
COPY docker-entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["/etc/docker/registry/config.yml"]
2)拉取注册服务镜像 registry;
docker pull registry:2.7.1
root@ubuntu:/#
root@ubuntu:/# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry 2.7.1 2d4f4b5309b1 3 weeks ago 26.2MB
redis 6.0.5 235592615444 4 weeks ago 104MB
mysql 8.0.20 be0dbf01a0f3 4 weeks ago 541MB
root@ubuntu:/#
mkdir /export/registry,创建目录,供 registry 容器挂载的数据卷
root@ubuntu:/#
root@ubuntu:/# mkdir /export/registry
root@ubuntu:/# cd /export/
root@ubuntu:/export# ll
total 16
drwxr-xr-x 4 root root 4096 Jul 11 06:43 ./
drwxr-xr-x 21 root root 4096 Jul 10 20:07 ../
drwxr-xr-x 4 root root 4096 Jul 10 20:07 redis/
drwxr-xr-x 2 root root 4096 Jul 11 06:43 registry/
root@ubuntu:/export#
3)启动 registry 容器
docker run -id --name zmf_registry -p 5000:5000 -v /export/registry:/var/lib/registry registry:2.7.1
root@ubuntu:/#
root@ubuntu:/# docker run -id --name zmf_registry -p 5000:5000 -v /export/registry:/var/lib/registry registry:2.7.1
ee6b52ae99f1a93bf7fbfa719685e72619a19e6b78d52ee068fdfd326f02bba5
root@ubuntu:/#
root@ubuntu:/# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ee6b52ae99f1 registry:2.7.1 "/entrypoint.sh /etc…" 5 seconds ago Up 4 seconds 0.0.0.0:5000->5000/tcp zmf_registry
dfca3f311df5 redis:6.0.5 "docker-entrypoint.s…" 3 hours ago Up 3 hours 0.0.0.0:6379->6379/tcp zmf_redis
6c121adcdf95 mysql:8.0.20 "docker-entrypoint.s…" 4 hours ago Up 4 hours 0.0.0.0:3306->3306/tcp 33060/tcp zmf_mysql
root@ubuntu:/#
4)查看私有仓库中镜像
curl http://192.168.146.134:5000/v2/_catalog
目前还没有,只是刚创建的
root@ubuntu:/#
root@ubuntu:/# curl http://192.168.146.134:5000/v2/_catalog
{"repositories":[]}
root@ubuntu:/#
2、推自定义镜像至私有仓库
1)选择某一镜像打自定义标签,并推到私有仓库
docker tag mysql:8.0.20 192.168.146.134:5000/mymysql
docker push 192.168.146.134:5000/mymysql
root@ubuntu:/#
root@ubuntu:/# docker tag mysql:8.0.20 192.168.146.134:5000/mymysql
root@ubuntu:/#
root@ubuntu:/# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry 2.7.1 2d4f4b5309b1 3 weeks ago 26.2MB
redis 6.0.5 235592615444 4 weeks ago 104MB
192.168.146.134:5000/mymysql latest be0dbf01a0f3 4 weeks ago 541MB
mysql 8.0.20 be0dbf01a0f3 4 weeks ago 541MB
root@ubuntu:/# docker push 192.168.146.134:5000/mymysql
The push refers to repository [192.168.146.134:5000/mymysql]
Get https://192.168.146.134:5000/v2/: http: server gave HTTP response to HTTPS client
root@ubuntu:/#
2)发现 push 不成功,需要配置一下,给 docker 注册https协议,支持https访问
修改配置文件 /etc/docker/daemon.json 。
insecure-registries -----> 开放注册https协议
registry-mirrors -----> 仓库源
root@ubuntu:/#
root@ubuntu:/# vim /etc/docker/daemon.json
root@ubuntu:/#
root@ubuntu:/# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://xxxxxx.mirror.aliyuncs.com"]
"insecure-registries": ["192.168.146.134:5000"]
}
root@ubuntu:/#
修改配置后需要重新装载配置文件,和重启 docker。不然 push 还是不成功的。
systemctl daemon-reload 重新装载配置文件;
systemctl restart docker 重启 docker;
root@ubuntu:/#
root@ubuntu:/# docker push 192.168.146.134:5000/mymysql
The push refers to repository [192.168.146.134:5000/mymysql]
Get https://192.168.146.134:5000/v2/: http: server gave HTTP response to HTTPS client
root@ubuntu:/#
root@ubuntu:/# systemctl daemon-reload
root@ubuntu:/#
root@ubuntu:/# systemctl restart docker
root@ubuntu:/#
root@ubuntu:/# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ee6b52ae99f1 registry:2.7.1 "/entrypoint.sh /etc…" 25 minutes ago Exited (2) 12 seconds ago zmf_registry
dfca3f311df5 redis:6.0.5 "docker-entrypoint.s…" 4 hours ago Exited (0) 12 seconds ago zmf_redis
6c121adcdf95 mysql:8.0.20 "docker-entrypoint.s…" 5 hours ago Exited (0) 9 seconds ago zmf_mysql
root@ubuntu:/#
root@ubuntu:/# docker restart zmf_mysql zmf_redis zmf_registry
zmf_mysql
zmf_redis
zmf_registry
root@ubuntu:/#
root@ubuntu:/# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ee6b52ae99f1 registry:2.7.1 "/entrypoint.sh /etc…" 25 minutes ago Up 4 seconds 0.0.0.0:5000->5000/tcp zmf_registry
dfca3f311df5 redis:6.0.5 "docker-entrypoint.s…" 4 hours ago Up 4 seconds 0.0.0.0:6379->6379/tcp zmf_redis
6c121adcdf95 mysql:8.0.20 "docker-entrypoint.s…" 5 hours ago Up 5 seconds 0.0.0.0:3306->3306/tcp 33060/tcp zmf_mysql
root@ubuntu:/#
root@ubuntu:/# docker push 192.168.146.134:5000/mymysql
The push refers to repository [192.168.146.134:5000/mymysql]
fd6eae62c2af: Pushed
815032910417: Pushed
d9f2d665b85e: Pushed
5fe2aef9ecd8: Pushed
2de987586bdb: Pushed
3a2464d8e0c0: Pushed
44853bb67274: Pushed
61cbb8ea6481: Pushed
66c45123fd43: Pushed
c3f46b20a0d3: Pushed
365386a39e0e: Pushed
13cb14c2acd3: Pushed
latest: digest: sha256:0ba38ea9c478d1e98b2f0bc0cee5a62345c9f06f78c4b48123bdc70d8d224686 size: 2828
root@ubuntu:/#
3)查看私有仓库中镜像
curl http://192.168.146.134:5000/v2/_catalog
root@ubuntu:/#
root@ubuntu:/# curl http://192.168.146.134:5000/v2/_catalog
{"repositories":["mymysql"]}
root@ubuntu:/#
3、启动 docker 容器管理界面
1)拉取管理界面镜像
docker pull konradkleine/docker-registry-frontend:v2
root@ubuntu:/#
root@ubuntu:/# docker pull konradkleine/docker-registry-frontend:v2
v2: Pulling from konradkleine/docker-registry-frontend
85b1f47fba49: Pull complete
e3c64813de17: Pull complete
6e61107884ac: Pull complete
411f14e0e0fd: Pull complete
987d1071cd71: Pull complete
95913db6ef30: Pull complete
1eb7ee3fbde2: Pull complete
9b6f26b1b1a1: Pull complete
daa6941a3108: Pull complete
86cc842193a6: Pull complete
024ab6890532: Pull complete
af9b7d0cb338: Pull complete
02f33fb0dcad: Pull complete
e8275670ee05: Pull complete
1c1a56903b01: Pull complete
afc4e94602b9: Pull complete
df1a95efa681: Pull complete
d8bcb7be9e08: Pull complete
d9c69b7bcc4f: Pull complete
2a14b209069e: Pull complete
e7c2bcdf63d5: Pull complete
efc16e6bbbea: Pull complete
552460069ca8: Pull complete
e6b075740da3: Pull complete
9976bc800046: Pull complete
Digest: sha256:181aad54ee64312a57f8ccba5247c67358de18886d5e2f383b8c4b80a7a5edf6
Status: Downloaded newer image for konradkleine/docker-registry-frontend:v2
docker.io/konradkleine/docker-registry-frontend:v2
root@ubuntu:/#
root@ubuntu:/# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry 2.7.1 2d4f4b5309b1 3 weeks ago 26.2MB
redis 6.0.5 235592615444 4 weeks ago 104MB
192.168.146.134:5000/mymysql latest be0dbf01a0f3 4 weeks ago 541MB
mysql 8.0.20 be0dbf01a0f3 4 weeks ago 541MB
konradkleine/docker-registry-frontend v2 60d4b91e68fa 2 years ago 266MB
root@ubuntu:/#
2)启动管理界面容器
docker run -d --name zmf_docker-registry-frontend -e ENV_DOCKER_REGISTRY_HOST=192.168.146.134 -e ENV_DOCKER_REGISTRY_PORT=5000 -p 801:80 konradkleine/docker-registry-frontend:v2
实验下来,这里还必须用 v2 版本的,latest 版本不行有 bug;
root@ubuntu:/#
root@ubuntu:/# docker run -d --name zmf_docker-registry-frontend -e ENV_DOCKER_REGISTRY_HOST=192.168.146.134 -e ENV_DOCKER_REGISTRY_PORT=5000 -p 801:80 konradkleine/docker-registry-frontend:v2
b5f2a77c0873ab8ee9bab937467b883fe8f8c7481f1c7aed454fbe708ebcb54f
root@ubuntu:/#
root@ubuntu:/# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b5f2a77c0873 konradkleine/docker-registry-frontend:v2 "/bin/sh -c $START_S…" 4 seconds ago Up 3 seconds 443/tcp 0.0.0.0:801->80/tcp zmf_docker-registry-frontend
ee6b52ae99f1 registry:2.7.1 "/entrypoint.sh /etc…" 33 minutes ago Up 7 minutes 0.0.0.0:5000->5000/tcp zmf_registry
dfca3f311df5 redis:6.0.5 "docker-entrypoint.s…" 4 hours ago Up 7 minutes 0.0.0.0:6379->6379/tcp zmf_redis
6c121adcdf95 mysql:8.0.20 "docker-entrypoint.s…" 5 hours ago Up 7 minutes 0.0.0.0:3306->3306/tcp 33060/tcp zmf_mysql
root@ubuntu:/#
3)访问管理界面
http://192.168.146.134:801/home