Docker CLI - docker image build

本文详细介绍Docker映像构建的命令与选项,包括如何使用Dockerfile构建映像、设置资源限制、缓存策略及网络配置等。适用于希望深入了解Docker映像构建流程的专业人士。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

描述

从Dockerfile构建映像

用法

docker image build [OPTIONS] PATH | URL | -

选项

名字,速记默认描述
--add-host Add a custom host-to-IP mapping (host:ip) -----添加自定义主机到IP映射(host:ip)
--build-arg Set build-time variables -----设置构建时变量
--cache-from Images to consider as cache sources -----要考虑作为缓存源的映像
--cgroup-parent Optional parent cgroup for the container -----容器的可选父cgroup
--compress Compress the build context using gzip -----使用gzip压缩构建上下文
--cpu-period Limit the CPU CFS (Completely Fair Scheduler) period -----限制CPU CFS(完全公平计划程序)期间
--cpu-quota Limit the CPU CFS (Completely Fair Scheduler) quota -----限制CPU CFS(完全公平计划程序)配额
--cpu-shares , -c CPU shares (relative weight) -----CPU份额(相对权重)
--cpuset-cpus CPUs in which to allow execution (0-3, 0,1) -----允许执行的CPU(0-3,0,1)
--cpuset-mems MEMs in which to allow execution (0-3, 0,1) -----允许执行的MEM(0-3,0,1)
--disable-content-trusttrueSkip image verification -----跳过映像验证
--file , -f Name of the Dockerfile (Default is ‘PATH/Dockerfile’) -----Dockerfile的名称(默认为'PATH / Dockerfile')
--force-rm Always remove intermediate containers -----始终移除中间容器
--iidfile Write the image ID to the file -----将图像ID写入文件
--isolation Container isolation technology -----容器隔离技术
--label Set metadata for an image -----设置图像的元数据
--memory , -m Memory limit -----内存限制
--memory-swap Swap limit equal to memory plus swap: ‘-1’ to enable unlimited swap -----交换限制等于内存加交换:' - 1以启用无限制交换
--network API 1.25+
Set the networking mode for the RUN instructions during build -----在构建期间设置RUN指令的网络模式
--no-cache Do not use cache when building the image -----构建映像时不要使用缓存
--output , -o API 1.40+
Output destination (format: type=local,dest=path) -----输出目的地(格式:type = local,dest = path)
--platform experimental (daemon)API 1.32+
Set platform if server is multi-platform capable -----如果服务器具有多平台功能,则设置平台
--progressautoSet type of progress output (auto, plain, tty). Use plain to show container output -----设置进度输出类型(auto,plain,tty)。使用plain显示容器输出
--pull Always attempt to pull a newer version of the image -----始终尝试拉出较新版本的映像
--quiet , -q Suppress the build output and print image ID on success -----成功时禁止构建输出并打印映像ID
--rmtrueRemove intermediate containers after a successful build -----成功构建后删除中间容器
--secret API 1.39+
Secret file to expose to the build (only if BuildKit enabled): id=mysecret,src=/local/secret -----要暴露给构建的秘密文件(仅当启用了BuildKit时):id = mysecret,src = / local / secret
--security-opt Security options -----安全选项
--shm-size Size of /dev/shm -----/ dev / shm的大小
--squash experimental (daemon)API 1.25+
Squash newly built layers into a single new layer -----新构建的图层压缩到一个新图层中
--ssh API 1.39+
SSH agent socket or keys to expose to the build (only if BuildKit enabled) (format: default|[=|[,]]) -----SSH代理套接字或用于公开构建的密钥(仅当启用了BuildKit时)(格式:default |[=|[,]])
--stream experimental (daemon)API 1.31+
Stream attaches to server to negotiate build context -----Stream附加到服务器以协商构建上下文
--tag , -t Name and optionally a tag in the ‘name:tag’ format -----以“name:tag”格式命名和选择标记
--target Set the target build stage to build. -----设置要构建的目标构建阶段。
--ulimit Ulimit options -----Ulimit选项
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Thomas Kant

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

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

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

打赏作者

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

抵扣说明:

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

余额充值