DirectorySecurity advisories
Sign in

Directory

go logo

go

Last changed
Get started with latest for free
docker pull cgr.dev/chainguard/go

Need access to a specific version? Contact us.

Sign in for updates

Get notified of upcoming product changes, critical vulnerability notifications and patches and more.

Sign in
Versions
Overview
Provenance
Specifications
SBOM
Vulnerabilities
Advisories

Container image for building Go applications.

Download this Image

The image is available on cgr.dev:

docker pull cgr.dev/chainguard/go:latest

Secure-by-default Features

In Go 1.20, we default to using the new GODEBUG settings of tarinsecurepath=0 and zipinsecurepath=0. These can be disabled by clearing the GODEBUG environment variable, or by setting them to 1.

Learn more about these settings in the Go release notes.

Go Application Examples

This section contains two examples of how you can use the Go Chainguard Image to build an example Go application. For more information on working with this Image, check out our Getting Started with the Go Chainguard Image guide.

Host architecture example

Many Image directories in the public Chainguard Images GitHub repository, including the one for the Go Image, contain examples you can run to test out the given Image.

You can build the Go application in tests/hello/main.go using the host architecture of your local machine by cloning the GitHub repository and then navigating to the /images/go/ directory.

From there, run the following command:

docker run --rm -v "${PWD}:/work" -w /work/tests/hello \
    -e GOOS="$(go env GOOS)" -e GOARCH="$(go env GOARCH)" \
    cgr.dev/chainguard/go build -o /work/hello .

The example application will be built to ./hello:

./hello
Hello World!

Dockerfile example

The following example Dockerfile builds a hello-world program in Go and copies it on top of the cgr.dev/chainguard/static:latest base image:

FROM cgr.dev/chainguard/go:latest as build

WORKDIR /work

COPY <<EOF go.mod
module hello
go 1.19
EOF

COPY <<EOF main.go
package main
import "fmt"
func main() {
    fmt.Println("Hello World!")
}
EOF
RUN go build -o hello .

FROM cgr.dev/chainguard/static:latest

COPY --from=build /work/hello /hello
CMD ["/hello"]

Run the following command to build the demo image and tag it as go-hello-world:

docker build -t go-hello-world  .

Now you can run the image with:

docker run go-hello-world

You should get output like this:

Hello World!

It’s worth noting how small the resulting image is:

docker images go-hello-world
REPOSITORY       TAG       IMAGE ID       CREATED       SIZE
go-hello-world   latest    859fedabd532   5 hours ago   3.21MB
Licenses

Chainguard Images contain software packages that are direct or transitive dependencies. The following licenses were found in the "latest" version of this image:

  • Apache-2.0

  • BSD-2-Clause

  • BSD-3-Clause

  • GCC-exception-3.1

  • GPL-2.0-only

  • GPL-2.0-or-later

  • GPL-3.0-or-later

View more

For a complete list of licenses, please refer to this Image's SBOM.

Software license agreement

Related images

Category
featured
application
languages

Products

Chainguard Images

© 2024 Chainguard, Inc.