文章目录
- 发布镜像到DockerHub
- 发布镜像到自建Docker仓库(Harbor)
- 修改配置文件
- 在Linux服务器中登录Docker
- 打TAG
- PUSH提交镜像
- PULL拉取镜像
- 发布镜像到阿里云容器服务
- 在Linux服务器中登录Docker
- PUSH提交镜像
- PULL拉取镜像
发布镜像到DockerHub
本地我们镜像命名可能会不规范,发布时想重新命名进行发布到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. 登录阿里云进入镜像服务 创建命名空间
![在这里插入图片描述](/i/li/?n=2&i=images/blog/202312/30001154_658eefca8f21d10582.png?,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
![在这里插入图片描述](/i/li/?n=2&i=images/blog/202312/30001154_658eefcaa8f5629621.png?,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)![在这里插入图片描述](/i/li/?n=2&i=images/blog/202312/30001154_658eefcac27986944.png?,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)2. 创建镜像仓库
![在这里插入图片描述](/i/li/?n=2&i=images/blog/202312/30001154_658eefcadb00894802.png?,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)![在这里插入图片描述](/i/li/?n=2&i=images/blog/202312/30001155_658eefcb67f2934818.png?,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
3. 创建完成后会自动弹出说明
![在这里插入图片描述](/i/li/?n=2&i=images/blog/202312/30001155_658eefcb7fbd919502.png?,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
## 在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
```
**在阿里云上查看镜像**
![在这里插入图片描述](/i/li/?n=2&i=images/blog/202312/30001155_658eefcb9ed7f19268.png?,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
![在这里插入图片描述](/i/li/?n=2&i=images/blog/202312/30001155_658eefcbb7efb34192.png?,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
发现成功上传
## PULL拉取镜像
**在Linux服务器上拉取镜像**
![在这里插入图片描述](/i/li/?n=2&i=images/blog/202312/30001155_658eefcbda5e211192.png?,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)官方介绍
```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
发布镜像到自建Docker仓库(Harbor)
修改配置文件
修改需要提交的配置文件 /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服务地址
}
在Linux服务器中登录Docker
$ docker login 192.168.1.1:10080
Username: admin
Password:
打TAG
docker tag test:1.6 192.168.1.1:10080/bigdata/test:1.6
PUSH提交镜像
docker push 192.168.1.1:10080/bigdata/test:1.6
PULL拉取镜像
docker pull 192.168.1.1:10080/bigdata/test:1.6
发布镜像到阿里云容器服务
https://cr.console.aliyun.com/cn-hangzhou/instances
- 登录阿里云进入镜像服务 创建命名空间
2. 创建镜像仓库
- 创建完成后会自动弹出说明
在Linux服务器中登录Docker
登录阿里云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提交镜像
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
在阿里云上查看镜像
发现成功上传
PULL拉取镜像
在Linux服务器上拉取镜像
官方介绍
$ 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