Docker镜像的创建管理和发布

获取镜像主要分为一下三类,本文将逐一记述

  • pull from registry (online) 从registry拉取

    • public(公有)

    • private(私有)

  • load from file (offline) 文件导入 (离线)

  • build from Dockerfile (online) 从Dockerfile构建

一.pull from registry (online) 从registry拉取

主要从Dockerhub,Quay.io等获取

docker image pull nginx //默认获取最新版本
docker image pull nginx:1.20.0 //获取指定版本

docker image ls //显示当前本地已下载image

docker image rm ID //删除指定image 须确保镜像中无容器
docker image prune -a //清除没有容器的image

二.load from file (offline) 文件导入 (离线)

docker image save nginx -o nginx.image //保存image
docker image load -i nginx.image //导入image

★三.build from Dockerfile (online) 从Dockerfile构建

在本地安装python3环境,并编译hello.py,运行以下代码后

FROM ubuntu:20.04
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y python3.9 python3-pip python3.9-dev
ADD hello.py /
CMD ["python3", "/hello.py"]

出现ubuntu 20.04和hello的image,后通过run运行

docker image build -t hello:1.0 . //建立image
docker run -it hello //运行hello image

通过上传到dockerhub上实现云存储,必须有账号名前缀

docker image build -t madapangname/hello:1.0 . //建一个名称 同ID
docker image tag hello madapangname/hello:1.0 //建立一个Tag 同ID


docker login //登录docker
docker image push madapangname/hello:1.0 //推送到hub

docker pull madapangname/hello:1.0 //拉取

最后删除原有image再次拉取进行测试运行,正常显示hello.py的内容

4.使用commit将存在的container转为image

进行交互式模式时,想将修改后的container存为image使用如下命令

docker container commit 571 test 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值