Return to Image List

golang

golang

Golang is a programming language first developed at Google. It is a statically-typed language with syntax loosely derived from C, but with additional features such as garbage collection, type safety, some dynamic-typing capabilities, additional built-in types (e.g., variable-length arrays and key-value maps), and a large standard library.

See golang.org for more information

This image is built by IBM to run on the IBM Z architecture and is not affiliated with any other community that provides a version of this image.


License

View license information here

As with all Docker images, these likely also contain other software which may be under other licenses (such as Bash, etc from the base distribution, along with any direct or indirect dependencies of the primary software being contained).

As for any pre-built image usage, it is the image user's responsibility to ensure that any use of this image complies with any relevant licenses for all software contained within.


Versions

Use the pull string below for the version of this image you require.
1.19-alpine3.16 docker pull icr.io/ibmz/golang@sha256:dbf32e4388fec44ae0e16265aaa457b8b374aabc1ee2f2a9080fcc6c6333d682 Vulnerability Report08-17-2022
1.17.8-bullseye docker pull icr.io/ibmz/golang@sha256:3cb076fb252e9a49765b58a00c5725f7c46642c524144b1f2c6d4a6bae1e0689 Vulnerability Report03-15-2022
1.21.4-bullseye docker pull icr.io/ibmz/golang@sha256:08b1052e1abe1aa4f2cc6a002d65753a82d78f7506bb108763cdc4c331327c2c Vulnerability Report12-13-2023
Version Pull String Security (IBM Cloud) Created

Usage Notes

Building and Running a Go Binary in a Container:
The most straightforward way to use this image is to use a Go container as both the build and runtime environment. In your Dockerfile, writing something along the lines of the following will compile and run your project:

FROM icr.io/ibmz/golang:[version]

WORKDIR /go/src/app
COPY . .

RUN go get -d -v ./...
RUN go install -v ./...

CMD ["app"]

You can then build and run the Docker image:

docker build -t my-golang-app .

docker run -it --rm --name my-running-app my-golang-app

Compile your app inside the Docker container:
There may be occasions where it is not appropriate to run your app inside a container. To compile, but not run your app inside the Docker instance, you can write something like:

Note: As a security measure, bind mounts are disabled in ZCX. Instead, please use Docker Volumes as illustrated below.

docker create volume [your_volume]


docker run --rm -v [your_volume]:/usr/src/myapp -w /usr/src/myapp icr.io/ibmz/golang:[version] go build -v


This will add your current directory as a volume to the container, set the working directory to the volume, and run the command go build which will tell go to compile the project in the working directory and output the executable to myapp. Alternatively, if you have a Makefile, you can run the make command inside your container.

docker run --rm -v [your_volume]:/usr/src/myapp -w /usr/src/myapp icr.io/ibmz/golang:[version] make


Note: /go is world-writable to allow flexibility in the user which runs the container (for example, in a container started with --user 1000:1000, running go get github.com/example/... will succeed). While the 777 directory would be insecure on a regular host setup, there are not typically other processes or users inside the container, so this is equivilant to 700 for Docker usage, but allowing for --user flexibility.