本文介紹如何將本地的鏡像上傳到鏡像倉庫。以及上傳時遇到"denied: requested access to the resource is denied"的解決方法。
原文地址:代碼匯個人博客 http://www.codehui.net/info/57.html
在上一篇文章中,介紹了使用docker快速搭建nginx+php環境,本文介紹如何把修改過的鏡像上傳至鏡像倉庫。我們需要先在 Docker Hub上注冊一個賬號。
- 查看鏡像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest f09fe80eb0e7 7 days ago 109MB
php 7.1-fpm 7c5ccac5d47f 7 days ago 358MB
- 查看容器
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
51adb2df6004 php:7.1-fpm "docker-php-entrypoif" 6 hours ago Up 6 hours 0.0.0.0:9000->9000/tcp myphp-fpm
3218b3ad4e47 f09fe80eb0e7 "nginx -g 'daemon off" 7 hours ago Up 7 hours 0.0.0.0:80->80/tcp mynginx
從容器創建一個新的鏡像
[root@localhost ~]# docker commit -p -a "codehui" -m "test" 3218b3ad4e47 codehi/nginx:v1
sha256:1d8fca63675ac57bccb50f0dbdb6030e384c22ee673eecdcb04c915236778109
-a :提交的鏡像作者;
-m :提交時的說明文字;
-p :在commit時,將容器暫停。
再次查看鏡像,發現了本地新提交的codehi/nginx:v1
的鏡像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
codehi/nginx v1 1d8fca63675a 21 minutes ago 109MB
nginx latest f09fe80eb0e7 7 days ago 109MB
php 7.1-fpm 7c5ccac5d47f 7 days ago 358MB
- 然后登陸到
docker hub
[root@localhost ~]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: codehi
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
- 將
codehi/nginx:v1
鏡像推送到docker hub
倉庫中
[root@localhost ~]# docker push codehi/nginx:v1
The push refers to repository [docker.io/codehi/nginx]
67e805da8eae: Pushed
6b5e2ed60418: Mounted from library/nginx
92c15149e23b: Mounted from library/nginx
0a07e81f5da3: Mounted from library/nginx
v1: digest: sha256:729b836319d3f8bd501db5e7bfadc31d1a88f996b0e756f6fb6cd6abd4408962 size: 1156
登陸倉庫后台查看上傳成功
然后就可以在另一台服務器使用pull
方法下載這個鏡像
[root@localhost ~]# docker pull codehi/nginx:v1
v1: Pulling from codehi/nginx
6ae821421a7d: Already exists
da4474e5966c: Already exists
eb2aec2b9c9f: Already exists
96e30fa1efc1: Pull complete
Digest: sha256:422535f95685c43406e378b2c59a3a6564362a683ceac4b783b9d5cee347ae17
Status: Downloaded newer image for codehi/nginx:v1
push 時報錯 "denied: requested access to the resource is denied" 的解決方法
報這個錯說明tag需要改名字,由於之前commit
的時候沒有填tag
,導致這塊上傳不上去,解決辦法:
[root@localhost ~]# docker tag 1d8fca63675a codehi/nginx:v1