docker私有仓库

打标签

docker tag <image>:<tag> <ip>:<port>/<image>:<tag>

1
[root@chobon ~]# docker tag demo_service_20191230_184347:master 192.168.122.101:5000/library/demo_service:master

查看镜像是否已经创建好

1
2
3
4
[root@chobon ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
demo_service_20191230_184347 master e636d97a1326 46 hours ago 246MB
192.168.122.101:5000/library/demo_service master e636d97a1326 46 hours ago 246MB

推送镜像到私有仓库

1
2
[root@chobon ~]# docker push 192.168.122.101:5000/library/demo_service
Get https://192.168.122.101:5000/v2/: http: server gave HTTP response to HTTPS client

这里报错是因为docker默认是https,想要推送到私有仓库还得在docker配置文件里加上一条设置。

修改docker配置文件

修改文件 vi /etc/docker/daemon.json

1
2
3
4
5
[root@chobon ~]# vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://d8b3zdiw.mirror.aliyuncs.com"],
"insecure-registries": ["192.168.122.101:5000"]#新增
}

重新加载配置 systemctl daemon-reload 重启docker systemctl restart docker

重新推送镜像

1
2
3
4
5
6
7
8
9
10
11
[root@chobon ~]# docker push 192.168.122.101:5000/library/demo_service:master

The push refers to repository [192.168.122.101:5000/library/demo_service]
25c442adb32f: Pushed
51828ce7738a: Pushed
cd464e998e4f: Pushed
ade02cbbac9a: Pushed
e36299e0cdf7: Pushed
1be02b18dfe7: Pushed
831c5620387f: Pushed
master: digest: sha256:5cec75598864dcd5194024360695b8e74fd3e2aeadc3629e9b519222fd644673 size: 1794

查看私有仓库镜像

先删除本地镜像

1
2
3
4
5
6
[root@chobon ~]# docker rmi 192.168.122.101:5000/library/demo_service:master
Untagged: 192.168.122.101:5000/library/demo_service:master
Untagged: 192.168.122.101:5000/library/demo_service@sha256:5cec75598864dcd5194024360695b8e74fd3e2aeadc3629e9b519222fd644673
[root@chobon ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
demo_service_20191230_184347 master e636d97a1326 46 hours ago 246MB

从私有仓库拉取镜像

1
2
3
4
5
[root@chobon ~]# docker pull 192.168.122.101:5000/library/demo_service:master
master: Pulling from library/demo_service
Digest: sha256:5cec75598864dcd5194024360695b8e74fd3e2aeadc3629e9b519222fd644673
Status: Downloaded newer image for 192.168.122.101:5000/library/demo_service:master
192.168.122.101:5000/library/demo_service:master