我正在尝试使用 GoLand/Cloud Code 构建 Golang 微服务。但我似乎无法确定 Dockerfile
。
FROM --platform=linux/arm64 golang:1.20-alpine AS build_base
RUN apk add --no-cache git
# Set the Current Working Directory inside the container
WORKDIR /tmp/wave-service
# We want to populate the module cache based on the go.{mod,sum} files.
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
# Unit tests
# CGO_ENABLED=0 go test -v
# Build the Go app
RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o ./out/wave-service ./wave_microservice.go
# Start fresh from a smaller image
FROM --platform=linux/arm64 golang:1.20-alpine
RUN apk add ca-certificates
COPY --from=build_base /tmp/wave-service/out/wave-service /app/wave-service
RUN chmod a+x /app/wave-service
# This container exposes port 8080 to the outside world
EXPOSE 8080
# Run the binary program produced by `go install`
CMD ["/app/wave-service"]
返回错误
Waiting for deployments to stabilize...
- deployment/wave-service: container wave-service-container is backing off waiting to restart
- pod/wave-service-565995d854-hwhsm: container wave-service-container is backing off waiting to restart
> [wave-service-565995d854-hwhsm wave-service-container] exec /app/wave-service: exec format error
我尝试过使用架构和操作系统变量,但我似乎找不到这里发生的事情。
编辑:
skaffold.yml
apiVersion: skaffold/v4beta5
kind: Config
build:
artifacts:
- image: wave-service
context: wave-service
platforms: ["linux/amd64"]
docker:
dockerfile: Dockerfile
manifests:
rawYaml:
- k8s-pod.yaml
k8s-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: wave-service
spec:
containers:
- name: wave-service
image: wave-service
最佳答案
所以问题不是 docker,而是我的主要 go 文件。它没有使用包main
,所以永远找不到正确的编译入口点,改变它有效!
关于docker - M1 Mac 上的 Go Cloud Code/Docker 执行格式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76447749/