我正在尝试使用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
2条答案
按热度按时间i2byvkas1#
所以问题不在于docker,而是我的主要go文件。它没有使用
main
包,所以go没有找到正确的入口点来编译,改变它起作用了!qojgxg4l2#
M1 Mac不允许部署为
amd64
构建的映像,因为它们与arm64
不兼容。您需要做的是强制
trustBuilder
使用构建包进行部署。设置trustBuilder=true
指示包库信任构建器映像中的生命周期二进制文件,方法是将注册表凭据装载到映像中并允许它执行映像导出。通过这种方式,所有构建包都可以看到凭据。在
skaffold.yml
文件中添加trustBuilder
选项:为了完整起见,我指出the github issue与skaffold最新版本中添加的修复相关,以检查解决该问题的提交代码。