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

咨询GCP容器优化OS及GCE上运行的Go可执行文件的GOOS/GOARCH取值

Go Build Environment Variables for GCP Compute Engine & Container-Optimized OS

Great question—let’s break this down clearly for the GCP environments you’re targeting:

1. Google Compute Engine (GCE) Instances

Most standard GCE VMs (like N2, E2, C2 machine series) run on x86_64 architecture, so your build command should use:

  • GOOS=linux (nearly all default GCE base OS images are Linux-based)
  • GOARCH=amd64

Example build command:

GOOS=linux GOARCH=amd64 go build -o my-gce-app main.go

If you’re using ARM-based GCE instances (such as the T2A series), adjust the architecture value:

  • GOOS=linux
  • GOARCH=arm64

ARM build example:

GOOS=linux GOARCH=arm64 go build -o my-gce-arm-app main.go

Pro tip: To confirm your target instance’s architecture, SSH into it and run uname -m—you’ll get x86_64 for amd64 or aarch64 for arm64.

2. GCP Container-Optimized OS (COS)

COS is a lightweight Linux-based OS built for container workloads, so the OS value stays consistent:

  • GOOS=linux

The architecture value matches the underlying GCE instance’s CPU type:

  • For x86_64 COS instances: GOARCH=amd64
  • For ARM64 COS instances: GOARCH=arm64

x86_64 COS build example:

GOOS=linux GOARCH=amd64 go build -o my-cos-app main.go

Even if you’re running the binary inside a container on COS, these values still hold—containers share the host’s kernel architecture, so cross-compiling to the host’s GOARCH guarantees compatibility.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 04:10:51