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.23.1-alpine docker pull icr.io/ibmz/golang@sha256:c835914a7b283fd24cbc66eb8c6b6a86ad89a7408103d40a0e3546243753b77d Vulnerability Report09-10-2024
1.19-alpine3.16 docker pull icr.io/ibmz/golang@sha256:18bda549d68313a1c204918e0076e36a4ccc9f4150dd731210e7c0ef19998b71 Vulnerability Report09-30-2024
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.