本地我们镜像命名可能会不规范,发布时想重新命名进行发布到DockerHub我们可以使用docker tag
命令
格式
docker tag $IMAGEID $新的标签[:版本]
`docker tag 66c054090a43 [toc]
# 发布镜像到DockerHub
本地我们镜像命名可能会不规范,发布时想重新命名进行发布到DockerHub我们可以使用`docker tag`命令
格式
`docker tag $IMAGEID $新的标签[:版本]`
`docker tag 66c054090a43 jast/tag:1.0`
```
[root@test16 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jast-test-docker 0.1.0 66c054090a43 47 minutes ago 638MB
[root@test16 ~]# docker tag 66c054090a43 jast/tag:1.0
[root@test16 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jast-test-docker 0.1.0 66c054090a43 47 minutes ago 638MB
jast/tag 1.0 66c054090a43 47 minutes ago 638MB
```
登录
(需要先进行账号注册,地址:[https://hub.docker.com](https://hub.docker.com))
```
docker login -u username
```
发布
```
docker push jast/tag:1.0
```
# 发布镜像到自建Docker仓库(Harbor)
## 修改配置文件
修改需要提交的配置文件` /etc/docker/daemon.json`
```json
{
"registry-mirrors": [
"https://pv0k1ghm.mirror.aliyuncs.com",
"https://docker.mirrors.ustc.edu.cn",
"http://hub-mirror.c.163.com"
],
"max-concurrent-downloads": 10,
"log-driver": "json-file",
"log-level": "warn",
"log-opts": {
"max-size": "10m",
"max-file": "3"
},
"data-root": "/var/lib/docker",
"insecure-registries": [ "192.168.1.1:10080"], # 这里配置私有Docker服务地址
}
```
## 在Linux服务器中登录Docker
```shell
$ docker login 192.168.1.1:10080
Username: admin
Password:
```
## 打TAG
```shell
docker tag test:1.6 192.168.1.1:10080/bigdata/test:1.6
```
## PUSH提交镜像
```shell
docker push 192.168.1.1:10080/bigdata/test:1.6
```
## PULL拉取镜像
```shell
docker pull 192.168.1.1:10080/bigdata/test:1.6
```
# 发布镜像到阿里云容器服务
[https://cr.console.aliyun.com/cn-hangzhou/instances](https://cr.console.aliyun.com/cn-hangzhou/instances)
1. 登录阿里云进入镜像服务 创建命名空间
![在这里插入图片描述](https://img-blog.csdnimg.cn/000563f7e40b41f18578f8696fe77dad.jpeg)
![在这里插入图片描述](https://img-blog.csdnimg.cn/2c7d36f271fd4192b742c8e00de1038b.jpeg)![在这里插入图片描述](https://img-blog.csdnimg.cn/ae5905f678344bbb8e671f8939b9fae4.jpeg)2. 创建镜像仓库
![在这里插入图片描述](https://img-blog.csdnimg.cn/5647ee92a2594fedb9493351bb500626.jpeg)![在这里插入图片描述](https://img-blog.csdnimg.cn/ee3cbfd78b704f03b7d1ac0d8281e19b.jpeg)
3. 创建完成后会自动弹出说明
![在这里插入图片描述](https://img-blog.csdnimg.cn/2f81aeb0eaff4a41a2f85bf12baf587d.jpeg)
## 在Linux服务器中登录Docker
登录阿里云Docker Registry
```shell
$ docker login --username=tb7****6464 registry.cn-hangzhou.aliyuncs.com
```
> 用于登录的用户名为阿里云账号全名,密码为开通服务时设置的密码。
> 您可以在访问凭证页面修改凭证密码。
登录成功
```shell
[root@test16 ~]# docker login --username=username registry.cn-hangzhou.aliyuncs.com
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
```
## PUSH提交镜像
**push镜像到阿里云仓库**
官方介绍如下
```shell
$ docker login --username=aliyunUsername registry.cn-hangzhou.aliyuncs.com
$ docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test:[镜像版本号]
$ docker push registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test:[镜像版本号]
请根据实际镜像信息替换示例中的[ImageId]和[镜像版本号]参数。
```
实际操作
```
[root@test16 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jast-test-docker 0.1.0 66c054090a43 2 hours ago 638MB
[root@test16 ~]# docker tag 66c054090a43 registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test:0.0.1
[root@test16 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jast-test-docker 0.1.0 66c054090a43 2 hours ago 638MB
registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test 0.0.1 66c054090a43 2 hours ago 638MB
# 上传到阿里云仓库
[root@test16 ~]# docker push registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test:0.0.1
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test]
27b2dc42c067: Pushed
7e28f1f4e30c: Pushed
74ddd0ec08fa: Pushed
0.0.1: digest: sha256:20d452aa1528bb8e1f236781a74b9e5e4af657470dfb6936af6dbc827923c5aa size: 954
```
**在阿里云上查看镜像**
![在这里插入图片描述](https://img-blog.csdnimg.cn/7cce69c4f26543c783691a302e7b5c44.jpeg)
![在这里插入图片描述](https://img-blog.csdnimg.cn/eb35378b3b0e4318862f952742192f51.jpeg)
发现成功上传
## PULL拉取镜像
**在Linux服务器上拉取镜像**
![在这里插入图片描述](https://img-blog.csdnimg.cn/8570e8d77be543d1920a0379494ce274.jpeg)官方介绍
```shell
$ docker pull registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test:[镜像版本号]
```
实际拉取操作,可以看到我们拉取回来的镜像
```shell
[root@test16 ~]# docker pull registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test:0.0.1
0.0.1: Pulling from jast-zsh/jast-test
a1d0c7532777: Already exists
56ca049bf4be: Already exists
524200aa718d: Already exists
Digest: sha256:20d452aa1528bb8e1f236781a74b9e5e4af657470dfb6936af6dbc827923c5aa
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test:0.0.1
registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test:0.0.1
[root@test16 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test 0.0.1 66c054090a43 2 hours ago 638MB
```
#
jast/tag:1.0`
[root@test16 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jast-test-docker 0.1.0 66c054090a43 47 minutes ago 638MB
[root@test16 ~]# docker tag 66c054090a43 jast/tag:1.0
[root@test16 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jast-test-docker 0.1.0 66c054090a43 47 minutes ago 638MB
jast/tag 1.0 66c054090a43 47 minutes ago 638MB
登录
(需要先进行账号注册,地址:https://hub.docker.com)
docker login -u username
发布
docker push jast/tag:1.0
修改需要提交的配置文件 /etc/docker/daemon.json
{
"registry-mirrors": [
"https://pv0k1ghm.mirror.aliyuncs.com",
"https://docker.mirrors.ustc.edu.cn",
"http://hub-mirror.c.163.com"
],
"max-concurrent-downloads": 10,
"log-driver": "json-file",
"log-level": "warn",
"log-opts": {
"max-size": "10m",
"max-file": "3"
},
"data-root": "/var/lib/docker",
"insecure-registries": [ "192.168.1.1:10080"], # 这里配置私有Docker服务地址
}
$ docker login 192.168.1.1:10080
Username: admin
Password:
docker tag test:1.6 192.168.1.1:10080/bigdata/test:1.6
docker push 192.168.1.1:10080/bigdata/test:1.6
docker pull 192.168.1.1:10080/bigdata/test:1.6
https://cr.console.aliyun.com/cn-hangzhou/instances
登录阿里云Docker Registry
$ docker login --username=tb7****6464 registry.cn-hangzhou.aliyuncs.com
用于登录的用户名为阿里云账号全名,密码为开通服务时设置的密码。
您可以在访问凭证页面修改凭证密码。
登录成功
[root@test16 ~]# docker login --username=username registry.cn-hangzhou.aliyuncs.com
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
push镜像到阿里云仓库
官方介绍如下
$ docker login --username=aliyunUsername registry.cn-hangzhou.aliyuncs.com
$ docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test:[镜像版本号]
$ docker push registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test:[镜像版本号]
请根据实际镜像信息替换示例中的[ImageId]和[镜像版本号]参数。
实际操作
[root@test16 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jast-test-docker 0.1.0 66c054090a43 2 hours ago 638MB
[root@test16 ~]# docker tag 66c054090a43 registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test:0.0.1
[root@test16 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jast-test-docker 0.1.0 66c054090a43 2 hours ago 638MB
registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test 0.0.1 66c054090a43 2 hours ago 638MB
# 上传到阿里云仓库
[root@test16 ~]# docker push registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test:0.0.1
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test]
27b2dc42c067: Pushed
7e28f1f4e30c: Pushed
74ddd0ec08fa: Pushed
0.0.1: digest: sha256:20d452aa1528bb8e1f236781a74b9e5e4af657470dfb6936af6dbc827923c5aa size: 954
$ docker pull registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test:[镜像版本号]
实际拉取操作,可以看到我们拉取回来的镜像
[root@test16 ~]# docker pull registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test:0.0.1
0.0.1: Pulling from jast-zsh/jast-test
a1d0c7532777: Already exists
56ca049bf4be: Already exists
524200aa718d: Already exists
Digest: sha256:20d452aa1528bb8e1f236781a74b9e5e4af657470dfb6936af6dbc827923c5aa
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test:0.0.1
registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test:0.0.1
[root@test16 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-hangzhou.aliyuncs.com/jast-zsh/jast-test 0.0.1 66c054090a43 2 hours ago 638MB