在上一篇文章中,介绍了使用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