docker 创建image上传到 docker hub ,并下载

张映 发表于 2017-05-25

分类目录: 云计算

标签:, ,

docker容器跨系统的特性,这为我们快速的部署带了来方便。不管是导出也好,还是提交到docker hub都是不错的选择。

1,注册一个docker hub

www.docker.com

2,启动测试的image

 $ docker run -v /Users/zhangying/es:/mnt/es --name es -d -p 9200:9200 -p 9300:9300 elasticsearch:latest
6cc6733f6666255164ac10ae97a2663d383fd667f892370169e933443d3a9c62

在这里要注意一下-v这个参数,/Users/zhangying/es是系统中的目录,/mnt/es是容器内的目录,他们二个互通的,起到桥梁的作用。也就是说/mnt/es有什么,在/Users/zhangying/es里面就有什么。

3,添加镜像

 zhangyingdeMacBook-Pro:~ zhangying$ docker ps
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                                            NAMES
6cc6733f6666        elasticsearch:latest   "/docker-entrypoint.s"   6 seconds ago       Up 5 seconds        0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp   es

zhangyingdeMacBook-Pro:~ zhangying$ docker commit 6cc6733f6666 tankzhang/es:v1
sha256:85fc66558c3716a31becaa1b8c0ea48426686372b849bc8073ead70df11e79b2

zhangyingdeMacBook-Pro:~ zhangying$ docker tag hello-world  tankzhang/es:v2

zhangyingdeMacBook-Pro:~ zhangying$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
tankzhang/es        v1                  85fc66558c37        9 minutes ago       352.1 MB
elasticsearch       latest              d781cd4e3228        8 days ago          352.1 MB
centos              latest              8140d0c64310        13 days ago         192.6 MB
hello-world         latest              48b5124b2768        4 months ago        1.84 kB
tankzhang/es        v2                  48b5124b2768        4 months ago        1.84 kB

在这里要注意一下,docker commit和docker tag都可以添加一个本地的image,只不过方式不同。

4,命令行下登录docker hub

 zhangyingdeMacBook-Pro:~ zhangying$ 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: tankzhang
Password:
Login Succeeded

5,push image到docker hub

 zhangyingdeMacBook-Pro:~ zhangying$ docker push tankzhang/es:v1
The push refers to a repository [docker.io/tankzhang/es]
0aa287ceeac9: Pushed
336813522c73: Mounted from library/elasticsearch
97ab0c7682c1: Mounted from library/elasticsearch
b35de56683a6: Mounted from library/elasticsearch
74deba3d0efa: Mounted from library/elasticsearch
072c001dedf8: Mounted from library/elasticsearch
c646acc026aa: Mounted from library/elasticsearch
489541ca7cd1: Mounted from library/elasticsearch
592e8cc170cf: Mounted from library/elasticsearch
e152466a133c: Mounted from library/elasticsearch
349781dbc7e4: Waiting
d161109ec021: Waiting
836ba1f26fa6: Waiting
37149424dccd: Waiting
c59fa6cbcbd9: Waiting
8d4d1ab5ff74: Waiting 

zhangyingdeMacBook-Pro:~ zhangying$ docker push tankzhang/es:v2
The push refers to a repository [docker.io/tankzhang/es]
98c944e98de8: Pushed
v2: digest: sha256:2075ac87b043415d35bb6351b4a59df19b8ad154e578f7048335feeb02d0f759 size: 524

6,删除本地测试image,然后pull docker hub的image


zhangyingdeMacBook-Pro:~ zhangying$ docker rmi tankzhang/es:v2
Untagged: tankzhang/es:v2
Untagged: tankzhang/es@sha256:2075ac87b043415d35bb6351b4a59df19b8ad154e578f7048335feeb02d0f759

zhangyingdeMacBook-Pro:~ zhangying$ docker pull tankzhang/es:v2
v2: Pulling from tankzhang/es
Digest: sha256:2075ac87b043415d35bb6351b4a59df19b8ad154e578f7048335feeb02d0f759
Status: Downloaded newer image for tankzhang/es:v2

zhangyingdeMacBook-Pro:~ zhangying$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
tankzhang/es        v1                  85fc66558c37        38 minutes ago      352.1 MB
elasticsearch       latest              d781cd4e3228        8 days ago          352.1 MB
centos              latest              8140d0c64310        13 days ago         192.6 MB
hello-world         latest              48b5124b2768        4 months ago        1.84 kB
tankzhang/es        v2                  48b5124b2768        4 months ago        1.84 kB

 



转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/cloud/1856.html