参考:汤小洋老师的教学视频
docker学习笔记(一)【docker 介绍、卸载、安装、配置加速】
docker学习笔记(二)docker常用命令
docker学习笔记(三)镜像
docker学习笔记(四)使用docker搭建环境
1、打开阿里云官网
2、选择镜像地区
3、开通个人镜像服务
注意:这里设置的密码需要记住,因为后面登录仓库需要用到!!!!!!!!!!!!
4、创建命名空间
5、创建一个镜像仓库
创建仓库成功
6、将自己的推送到刚刚创建的阿里云镜像
6.1、登录仓库
[root@iz2zedg4ylq9iqtwm11wecz nginx]# docker login --username=娱乐明星 https://cr.console.aliyun.com/cn-shenzhen/instance/repositories
Password:
Login Succeeded
[root@iz2zedg4ylq9iqtwm11wecz nginx]#
解释
- 这里的–username 是:
- 后面的地址是:
- 密码是:开通个人服务的时候设置的密码
6.2、推送镜像
6.2.1、docker tag
这个命令并没有推送镜像,只是给镜像指定一个版本,这个版本不是指本地镜像的版本,而是推送后在阿里云仓库的版本。
[root@iz2zedg4ylq9iqtwm11wecz nginx]# docker tag c43a65faae57 registry.cn-shenzhen.aliyuncs.com/wuyujitang/dockerimages_wuyujitang:v1.0
[root@iz2zedg4ylq9iqtwm11wecz nginx]#
命令解释
- tag后面的是你要推送的镜像id
- 后面是你的镜像仓库地址,直接去创建好的仓库去复制 (注意这里复制的地址是错误的!!!!!直接跳到后看正确的地址)
- 最后面(:v1.0)是推送镜像的版本,这个自定义就好。
6.2.2、docker push
[root@iz2zedg4ylq9iqtwm11wecz nginx]# docker push registry.cn-shenzhen.aliyuncs.com/wuyujitang/dockerimages_wuyujitang:v1.0
The push refers to a repository [registry.cn-shenzhen.aliyuncs.com/wuyujitang/dockerimages_wuyujitang]
daf63ef0ddbb: Preparing
3307ffa538c1: Preparing
8f8b5acac684: Preparing
15786a1cf1cb: Preparing
6f770cdc9ebf: Preparing
3fc095fab4a2: Waiting
685934357c89: Waiting
ccb9b68523fd: Waiting
00bcea93703b: Waiting
688e187d6c79: Waiting
denied: requested access to the resource is denied
[root@iz2zedg4ylq9iqtwm11wecz nginx]#
在推送的过程中可能会失败(这里失败的原因是:拒绝:请求的对资源的访问被拒绝),这是因为我推送的镜像是别人官方的镜像。被拒绝推送了。
我们百度一下,别人的解释是在构建自己的Dockerfile的时候需要指定作者。
因此,我们通过之前构建好Dockerfile,构建一个自己的镜像
[root@iz2zedg4ylq9iqtwm11wecz tmp]# cd /tmp
[root@iz2zedg4ylq9iqtwm11wecz tmp]# ls
DockerFile2 mysqlx.sock
Dockerflie php-cgi-70.sock
hsperfdata_root systemd-private-1834ff36204f4f2d946848661d4da1da-ntpd.service-CTDxLR
hsperfdata_www tmp.INpwCFw96T
index.jsp tmp.wc6ZL9XBpo
mysql.sock tomcat
[root@iz2zedg4ylq9iqtwm11wecz tmp]# docker build -f Dockerflie -t wuyujitng.top/mytomcat:v1Dockerfile .
Sending build context to Docker daemon 250.9 kB
Step 1/5 : FROM tomcat
---> c43a65faae57
Step 2/5 : MAINTAINER 123123@qq.com
---> Running in 17f8b07b4e66
---> cd8493245e2c
Removing intermediate container 17f8b07b4e66
Step 3/5 : RUN touch /usr/local/tomcat/webapps/aaa.txt
---> Running in 01ee909971d0
---> c1024169fe20
Removing intermediate container 01ee909971d0
Step 4/5 : RUN echo "hello word DockerFile! " > /usr/local/tomcat/webapps/index.jsp
---> Running in b2417166e1b9
---> 45e7cc72fcb6
Removing intermediate container b2417166e1b9
Step 5/5 : RUN cat /usr/local/tomcat/webapps/index.jsp
---> Running in 0e95e2c5df0d
hello word DockerFile!
---> 492750dd885b
Removing intermediate container 0e95e2c5df0d
Successfully built 492750dd885b
[root@iz2zedg4ylq9iqtwm11wecz tmp]#
再次尝试push镜像
额!再次尝试也失败了,原来是上面复制的地址有问题。
其实,官方已经给出了教程。!!!!!!!
按照里面的地址来push就成功了
[root@iz2zedg4ylq9iqtwm11wecz tmp]# docker tag 55e93b69ba15 registry.cn-shenzhen.aliyuncs.com/wuyujitang/dockerimages_wuyujitang:v11.1
[root@iz2zedg4ylq9iqtwm11wecz tmp]# docker push registry.cn-shenzhen.aliyuncs.com/wuyujitang/dockerimages_wuyujitang:v11.1
The push refers to a repository [registry.cn-shenzhen.aliyuncs.com/wuyujitang/dockerimages_wuyujitang]
6c3fc2cec9e2: Pushed
5c14bc9e2ce5: Pushed
daf63ef0ddbb: Pushed
3307ffa538c1: Pushed
8f8b5acac684: Pushed
15786a1cf1cb: Pushed
6f770cdc9ebf: Pushed
3fc095fab4a2: Pushed
685934357c89: Pushed
ccb9b68523fd: Pushed
00bcea93703b: Pushed
688e187d6c79: Pushed
v11.1: digest: sha256:b7af4ffae0b94ccd36fb71967f046f907cd70d399d3cd0f1cbc1d8f81f1ca48c size: 2835
[root@iz2zedg4ylq9iqtwm11wecz tmp]#
6.2.3、在阿里云仓库查看镜像
6.2.4、拉取自己push到阿里云仓库的镜像
这里拉取后已经成功了,因为本地存在的镜像是最新版的,所以就没有去仓库下载。
[root@iz2zedg4ylq9iqtwm11wecz tmp]# docker pull registry.cn-shenzhen.aliyuncs.com/wuyujitang/dockerimages_wuyujitang:v11.1
Trying to pull repository registry.cn-shenzhen.aliyuncs.com/wuyujitang/dockerimages_wuyujitang ...
v11.1: Pulling from registry.cn-shenzhen.aliyuncs.com/wuyujitang/dockerimages_wuyujitang
Digest: sha256:b7af4ffae0b94ccd36fb71967f046f907cd70d399d3cd0f1cbc1d8f81f1ca48c
Status: Image is up to date for registry.cn-shenzhen.aliyuncs.com/wuyujitang/dockerimages_wuyujitang:v11.1
[root@iz2zedg4ylq9iqtwm11wecz tmp]#
可以先删除本地的镜像再次拉取
[root@iz2zedg4ylq9iqtwm11wecz tmp]# docker rmi -f 55e93b69ba15
Untagged: registry-vpc.cn-shenzhen.aliyuncs.com/wuyujitang/dockerimages_wuyujitang:v1.0
Untagged: registry.cn-shenzhen.aliyuncs.com/wuyujitang/dockerimages_wuyujitang:v11.1
Untagged: registry.cn-shenzhen.aliyuncs.com/wuyujitang/dockerimages_wuyujitang@sha256:b7af4ffae0b94ccd36fb71967f046f907cd70d399d3cd0f1cbc1d8f81f1ca48c
Untagged: wuyujitng.top/mytomcat:v1Dockerfile
Deleted: sha256:55e93b69ba150c39ccc4c57dda82299880b70b0ed163447939b4e39217c29612
Deleted: sha256:b37188be4531f2fd10feb8179031b51ab4048898343ee571fcc87575b3caf05a
Deleted: sha256:7fb61f24f7f681642317e69cc3fdc53e1922cf2bc33895abfda90fbe5d5daf61
Deleted: sha256:ef8a810374974bbc39231407d4a3a4b70640ef27db6e2b09ec6bf582f23d4cbd
Deleted: sha256:62fe8402adbe74cbcde479d24fb60616aa263cd57025661a493def906e177137
Deleted: sha256:fd9331adfdf64106ba6e16112c79c344f5479c007ee47b311ded7767fe6a0368
[root@iz2zedg4ylq9iqtwm11wecz tmp]# docker pull registry.cn-shenzhen.aliyuncs.com/wuyujitang/dockerimages_wuyujitang:v11.1
Trying to pull repository registry.cn-shenzhen.aliyuncs.com/wuyujitang/dockerimages_wuyujitang ...
v11.1: Pulling from registry.cn-shenzhen.aliyuncs.com/wuyujitang/dockerimages_wuyujitang
d960726af2be: Already exists
e8d62473a22d: Already exists
8962bc0fad55: Already exists
65d943ee54c1: Already exists
da20b77f10ac: Already exists
8669a096f083: Already exists
e0c0a5e9ce88: Already exists
f7f46169d747: Already exists
42d8171e56e6: Already exists
774078a3f8bb: Already exists
c6ad866d3e3f: Pull complete
8f1a6d86480a: Pull complete
Digest: sha256:b7af4ffae0b94ccd36fb71967f046f907cd70d399d3cd0f1cbc1d8f81f1ca48c
Status: Downloaded newer image for registry.cn-shenzhen.aliyuncs.com/wuyujitang/dockerimages_wuyujitang:v11.1
[root@iz2zedg4ylq9iqtwm11wecz tmp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-shenzhen.aliyuncs.com/wuyujitang/dockerimages_wuyujitang v11.1 55e93b69ba15 27 minutes ago 667 MB
docker.io/nginx latest d1a364dc548d 2 days ago 133 MB
docker.io/tomcat latest c43a65faae57 2 weeks ago 667 MB
docker.io/redis latest bc8d70f9ef6c 2 weeks ago 105 MB
docker.io/mysql 5.7 2c9028880e58 2 weeks ago 447 MB
docker.io/centos latest 300e315adb2f 5 months ago 209 MB
[root@iz2zedg4ylq9iqtwm11wecz tmp]#