https://github.com/brimstone/docker-golang
Docker image for cross compiling go with CGO for linux (desktops and Raspberry Pis), Windows, MacOS, and FreeBSD
https://github.com/brimstone/docker-golang
docker-image freebsd golang linux musl raspberrypi windows
Last synced: about 1 year ago
JSON representation
Docker image for cross compiling go with CGO for linux (desktops and Raspberry Pis), Windows, MacOS, and FreeBSD
- Host: GitHub
- URL: https://github.com/brimstone/docker-golang
- Owner: brimstone
- Created: 2018-09-04T12:47:55.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2025-04-01T19:00:13.000Z (about 1 year ago)
- Last Synced: 2025-04-12T10:05:39.378Z (about 1 year ago)
- Topics: docker-image, freebsd, golang, linux, musl, raspberrypi, windows
- Language: Shell
- Homepage:
- Size: 123 KB
- Stars: 6
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
golang
======
This is a container to build golang static binaries with cgo musl for amd64, glibc for darwin, freebsd, and windows
[![microbadger][1]][2] [![docker hub][3]][4]
[1]: https://images.microbadger.com/badges/image/brimstone/golang.svg
[2]: https://microbadger.com/images/brimstone/golang
[3]: https://img.shields.io/docker/automated/brimstone/golang.svg
[4]: https://hub.docker.com/r/brimstone/golang
Usage
-----
Check out your source files to a GOPATH compatible directory:
```bash
mkdir -p src/github.com/user
git clone https://github.com/user/repo.git src/github.com/user/repo
```
Then build!
```bash
docker run --rm -it -v "$PWD:/go" -u "$UID:$GID" brimstone/golang github.com/user/repo
```
Alternate build
---------------
For when another repo is included in a `src` directory, for instance, a submodule:
```bash
tar c src \
| docker run --rm -i -e TAR=1 brimstone/golang github.com/user/repo \
| tar -x ./main
```
For when there's just source files in a diretory:
```bash
tar c . \
| docker run --rm -i -e TAR=1 brimstone/golang -o main \
| tar -x ./main
```
Environment Variables
---------------------
`VERBOSE` This makes the loader script more verbose
ONBUILD
-------
This image supports docker multistage builds. Simply use this as template for your Dockerfile:
```
ARG REPOSITORY=github.com/brimstone/example
FROM brimstone/golang as builder
FROM scratch
ENV ADDRESS=
EXPOSE 80
ENTRYPOINT ["/repo", "serve"]
COPY --from=builder /app /repo
```
Then build with this:
```
docker build -t user/repo --build-arg PACKAGE=github.com/user/repo .
```
References
----------
http://dominik.honnef.co/posts/2015/06/statically_compiled_go_programs__always__even_with_cgo__using_musl/