Docker:阿里云容器镜像服务的基本使用
2019-03-04 00:43
786 查看
远程仓库有很多,这里选用阿里云容器镜像服务
注册阿里云容器镜像服务
Docker登录仓库
$ docker login registry.cn-hangzhou.aliyuncs.com Username: vczyh Password: WARNING! Your password will be stored unencrypted in /home/vczyh/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded
Username:阿里云账号
Password:第一步注册的密码,不是阿里云登录密码
可以查看
~/.docker/config.json
{ "auths": { // 每登录一个仓库,就会添加一条记录 // 官方默认仓库 如果没有登录过官方仓库就没有这条记录 "https://index.docker.io/v1/": { "auth": "xxxxxxxx" }, // 阿里云杭州仓库 "registry.cn-hangzhou.aliyuncs.com": { "auth": "xxxxxxxx" } }, "HttpHeaders": { "User-Agent": "Docker-Client/18.09.3 (linux)" } }
创建命名空间
Push镜像
push之前需要给镜像打标签,让镜像的格式符合push格式:
registry.cn-hangzhou.aliyuncs.com/acs/agent:0.8
registry.cn-hangzhou.aliyuncs.com
是Registry的域名。acs
是您所使用的命名空间的名称。agent
是您所使用的仓库的名称。0.8
是镜像标签(Tag)。非必须,默认为latest。
将这几个完全独立的概念组合一下,还有以下概念。
registry.cn-hangzhou.aliyuncs.com/acs/agent
称为仓库坐标。acs/agent
称为仓库全名(通常在API中使用)。
格式:
git tag 镜像名或镜像ID Registry的域名/命名空间/仓库名称[:TAG]
比如:
docker tag friendlyhello:latest registry.cn-hangzhou.aliyuncs.com/zhangyuheng/hello:1.0
friendlyhello是本地镜像的名字,我想把它推送到阿里云杭州Registry的命名空间为
zhangyuehng的仓库,并且把远程仓库名设置为
hello,远程仓库的
TAG为1.0
push:
$ docker push registry.cn-hangzhou.aliyuncs.com/zhangyuheng/hello The push refers to repository [registry.cn-hangzhou.aliyuncs.com/zhangyuheng/hello] 6a16fc072b92: Pushed 25207160ad9f: Pushed ea960483fa9a: Pushed 4c17a5d758f3: Pushed 7e6d2caa6460: Pushed ba1d5b7b438f: Pushed 0a07e81f5da3: Pushed 1.0: digest: sha256:0ce58a5951363980bf04af8ebbe43c3aeb5c7509b0cfc852cf05f6ee3f81c179 size: 1787
为什么要在push之前先生成另一个镜像,原因就是在push的时候可以让Docker通过镜像名分辨出要推送到哪里
查看远程仓库
Pull镜像
docker pull registry.cn-hangzhou.aliyuncs.com/zhangyuheng/hello:1.0
运行远程仓库镜像
先删除本地镜像,不然会直接运行本地镜像
docker rmi registry.cn-hangzhou.aliyuncs.com/zhangyuheng/hello:1.0
下载镜像并运行
$ docker run -p 4000:80 registry.cn-hangzhou.aliyuncs.com/zhangyuheng/hello:1.0 Unable to find image 'registry.cn-hangzhou.aliyuncs.com/zhangyuheng/hello:1.0' locally 1.0: Pulling from zhangyuheng/hello Digest: sha256:0ce58a5951363980bf04af8ebbe43c3aeb5c7509b0cfc852cf05f6ee3f81c179 Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/zhangyuheng/hello:1.0 * Serving Flask app "app" (lazy loading) * Environment: production WARNING: Do not use the development server in a production environment. Use a production WSGI server instead. * Debug mode: off * Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
相关文章推荐
- Docker使用Dockerfile创建支持ssh服务自启动的容器镜像
- 使用Dockerfile创建nginx服务容器镜像
- Docker微服务-镜像构建交付和使用Rancher进行容器创建管理
- Docker使用Dockerfile创建支持ssh服务自启动的容器镜像
- Docker使用Dockerfile创建支持ssh服务自启动的容器镜像
- 使用Dockerfile创建支持ssh服务自启动的容器镜像
- Docker使用Dockerfile创建支持ssh服务自启动的容器镜像
- 【下一代核心技术DevOps】:(四)私有镜像库阿里云Docker服务使用
- Docker使用Dockerfile创建支持ssh服务自启动的容器镜像
- Docker使用Dockerfile创建支持ssh服务自启动的容器镜像
- spring boot 使用docker在阿里云容器服务部署
- 使用阿里云容器Hub加速Docker镜像下载
- Docker使用Dockerfile创建支持ssh服务自启动的容器镜像
- 使用Dockerfile构建支持ssh服务自启动的容器镜像
- Docker创建支持ssh服务的容器和镜像
- Ubuntu14.04中使用docker容器部署tomcat镜像+java web项目
- 阿里云容器服务与ASP.NET Core部署:用 docker secrets 保存 appsettings.Production.json
- docker容器的基本使用
- 品尝阿里云容器服务:用nginx镜像创建容器,体验基于域名的路由机制