在上一篇文章中,介绍了使用docker快速搭建nginx+php环境,本文介绍如何把修改过的镜像上传至镜像仓库。我们需要先在 Docker Hub上注册一个账号。
- 查看镜像
[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEnginx latest f09fe80eb0e7 7 days ago 109MBphp 7.1-fpm 7c5ccac5d47f 7 days ago 358MB
- 查看容器
[root@localhost ~]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES51adb2df6004 php:7.1-fpm "docker-php-entrypoif" 6 hours ago Up 6 hours 0.0.0.0:9000->9000/tcp myphp-fpm3218b3ad4e47 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:v1sha256:1d8fca63675ac57bccb50f0dbdb6030e384c22ee673eecdcb04c915236778109
-a :提交的镜像作者;
-m :提交时的说明文字;
-p :在commit时,将容器暂停。
再次查看镜像,发现了本地新提交的codehi/nginx:v1的镜像
[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEcodehi/nginx v1 1d8fca63675a 21 minutes ago 109MBnginx latest f09fe80eb0e7 7 days ago 109MBphp 7.1-fpm 7c5ccac5d47f 7 days ago 358MB
- 然后登陆到
docker hub
[root@localhost ~]# docker loginLogin 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: codehiPassword:WARNING! Your password will be stored unencrypted in /root/.docker/config.json.Configure a credential helper to remove this warning. Seehttps://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded
- 将
codehi/nginx:v1镜像推送到docker hub仓库中
[root@localhost ~]# docker push codehi/nginx:v1The push refers to repository [docker.io/codehi/nginx]67e805da8eae: Pushed6b5e2ed60418: Mounted from library/nginx92c15149e23b: Mounted from library/nginx0a07e81f5da3: Mounted from library/nginxv1: digest: sha256:729b836319d3f8bd501db5e7bfadc31d1a88f996b0e756f6fb6cd6abd4408962 size: 1156
登陆仓库后台查看上传成功

然后就可以在另一台服务器使用pull方法下载这个镜像
[root@localhost ~]# docker pull codehi/nginx:v1v1: Pulling from codehi/nginx6ae821421a7d: Already existsda4474e5966c: Already existseb2aec2b9c9f: Already exists96e30fa1efc1: Pull completeDigest: sha256:422535f95685c43406e378b2c59a3a6564362a683ceac4b783b9d5cee347ae17Status: 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
