You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Docker Buildx为镜像添加latest标签并推送

解决Buildx构建多架构镜像后添加latest标签的问题

你遇到的问题是因为Docker Buildx默认使用docker-container驱动进行多架构构建,这种模式下构建的镜像不会保存到本地Docker镜像仓库,而是直接推送到远程仓库,所以本地找不到stanleysathler/terraform-starter-carts-api:1.0.0镜像。

下面是两种可行的解决方案:

方案一:构建时直接添加多个标签(推荐)

在Buildx构建命令中同时指定1.0.0和latest两个标签,一次完成构建与推送,无需后续操作:

docker buildx build \
    --push \
    --platform linux/amd64,linux/arm64 \
    --tag stanleysathler/terraform-starter-carts-api:1.0.0 \
    --tag stanleysathler/terraform-starter-carts-api:latest \
    --file carts-api/docker/Dockerfile \
    ./carts-api

方案二:为已推送的镜像添加新标签

如果已经完成了1.0.0版本的推送,可以使用Buildx的imagetools子命令直接在远程仓库创建新标签,无需拉取镜像到本地:

docker buildx imagetools create \
    -t stanleysathler/terraform-starter-carts-api:latest \
    stanleysathler/terraform-starter-carts-api:1.0.0

这个命令会让latest标签指向与1.0.0完全相同的多架构镜像manifest,完成标签添加与推送。

注意:不要使用docker tag+docker push的方式,因为本地没有多架构镜像,强行拉取的话只能获取对应本地架构(arm64)的镜像,推送后的latest标签会变成单架构,不符合你的需求。

内容的提问来源于stack exchange,提问作者Stanley Sathler

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 00:10:11