Docker 远程仓库拉取镜像并在构建本地镜像后将镜像推送到远程

镜像拉取

// A code block
[unique@localhost ~]$  sudo docker pull username/repository:tag 

启动本地容器

// A code block
localhost:Data sunkaixin$ docker images
REPOSITORY                                         TAG                 IMAGE ID            CREATED             SIZE
reg.docker.haha-inoc.com/hahabase/alios7u2        latest              43d2d59ab537        4 months ago        2.8GB
reg.docker.haha-inoc.com/soag/jpgmon_servicetest  1.0                 3afd24b0b6b1        7 months ago        3.96GB
reg.docker.haha-inoc.com/sla/ipgmon               1.0                 24bdf509bbda        15 months ago       2.97GB
reg.docker.haha-inoc.com/sla/jpgmon              <none>               72d693f8898e        15 months ago       3.05GB

拉起本地镜像

// A code block
localhost:Data sunkaixin$ docker run -itd 3afd24b0b6b1

查找容器并进入

安装必要的软件
Docker tag
标记image

将本地映像与注册表上的存储库相关联的表示法是 username/repository:tag。标签是可选的,但建议使用,因为它是注册管理机构用来为Docker镜像提供版本的机制。为上下文提供存储库和标记有意义的名称,例如 get-started:part2。这会将图像放入get-started存储库并将其标记为part2。

现在,把它们放在一起来标记图像。docker tag image使用您的用户名,存储库和标记名称运行,以便将图像上载到所需的目标位置。该命令的语法是:

docker tag imageName  username/repository:tag

docker build && commit
docker build命令用于根据给定的Dockerfile和上下文以构建Docker镜像。

docker build命令的使用格式:
docker build [OPTIONS] <PATH | URL | ->

  1. 常用OPTIONS选项说明
    –build-arg,设置构建时的环境变量
    –no-cache,默认false。设置该选项,将不使用Build Cache构建镜像
    –pull,默认false。设置该选项,总是尝试pull镜像的最新版本
    –compress,默认false。设置该选项,将使用gzip压缩构建的上下文
    –disable-content-trust,默认true。设置该选项,将对镜像进行验证
    –file, -f,Dockerfile的完整路径,默认值为‘PATH/Dockerfile’
    –isolation,默认–isolation=“default”,即Linux命名空间;其他还有process或hyperv
    –label,为生成的镜像设置metadata
    –squash,默认false。设置该选项,将新构建出的多个层压缩为一个新层,但是将无法在多个镜像之间共享新层;设置该选项,实际上是创建了新image,同时保留原有image。
    –tag, -t,镜像的名字及tag,通常name:tag或者name格式;可以在一次构建中为一个镜像设置多个tag
    –network,默认default。设置该选项,Set the networking mode for the RUN instructions during build
    –quiet, -q ,默认false。设置该选项,Suppress the build output and print image ID on success
    –force-rm,默认false。设置该选项,总是删除掉中间环节的容器
    –rm,默认–rm=true,即整个构建过程成功后删除中间环节的容器
// docker commit
docker commit -m "xxx" <容器 id> <镜像名称>:<tag>

docker push

//docer push
docker push username/repository:tag

在这里插入图片描述

step1——找到本地镜像的ID:docker images

step2——登陆Hub:docker login --username=username --password=password --email=email

step3——tag:docker tag <imageID> <namespace>/<image name>:<version tag eg latest>

step4——push镜像:docker push <namespace>/<image name>
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

漫漫开发路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值