docker build keep building 错误的架构

docker build keep building wrong architecture

以下 Dockerfile 不断构建错误的架构:

注意我不能使用 buildx,因为我需要为不同的架构安装特定的工具

arm64/Dockerfile

# syntax=docker/dockerfile:1

# Download arm64 specifict tools

FROM golang:1.17.2 as build

WORKDIR /source

COPY src/go.mod ./
COPY src/go.sum ./
RUN go mod download

COPY src/ ./
RUN env GOOS=linux GOARCH=arm64 go build -o /app

docker 建造:

docker build \
--target build -t $CURRENT_REGISTRY/mycontainer:arm64 \
-f ./docker/$ARCH/Dockerfile .

docker 检查:

docker inspect manifest $CURRENT_REGISTRY/mycontainer:arm64

输出:(应该是arm64而不是amd64)?

 ...
 "Architecture": "amd64",
        "Os": "linux",
        "Size": 323727784,
        "VirtualSize": 323727784,
 ...

只需在每个平台上使用 docker buildx build 而不是 build。然后使用 docker docker manifest create.