docker - M1 Mac 上的 Go Cloud Code/Docker 执行格式错误

标签 docker dockerfile goland google-cloud-code google-cloud-intellij

我正在尝试使用 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/

相关文章:

intellij-idea - 智能 IDEA。检查没有扩展名的文件的语法

intellij-idea - intellij 和 goland 之间共享热键设置吗?

windows - Windows 10 上 Docker for Windows 中的 DOCKER_CERT_PATH 是什么?

php - Dockerfile - RUN apt-get install -y php5-MODULES 不再工作 -'has no installation candidate' 。如何解决?

docker - 使用来自不同存储库的代码运行多个 Docker 容器的最佳实践是什么?

go - 如何配置 goland 识别 'mod' 包?

curl - Jenkins 无法 curl 到 docker 容器上的 http 端点主机

docker - [kubeadm] 更新 cni 配置时出错

dockerfile - Linux Alpine 的默认用户是什么?

docker - Dockerfile 中的开发依赖项或用于生产和测试的单独 Dockerfile