Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bnkamalesh/golang-dockerfile
Dockerfiles for building Go application images
https://github.com/bnkamalesh/golang-dockerfile
docker docker-image dockerfile go go-application golang golang-docker golang-docker-starter
Last synced: 2 months ago
JSON representation
Dockerfiles for building Go application images
- Host: GitHub
- URL: https://github.com/bnkamalesh/golang-dockerfile
- Owner: bnkamalesh
- License: mit
- Created: 2020-02-28T05:13:34.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-03-13T10:36:07.000Z (10 months ago)
- Last Synced: 2024-06-20T10:13:46.761Z (6 months ago)
- Topics: docker, docker-image, dockerfile, go, go-application, golang, golang-docker, golang-docker-starter
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 16
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go Dockerfile v0.1.6
[Dockerfiles](https://docs.docker.com/engine/reference/builder/) to build [Docker images](https://docs.docker.com/engine/docker-overview/#docker-objects) for your [Go](https://go.dev) app. It makes use of Docker's [multi-stage build feature](https://docs.docker.com/develop/develop-images/multistage-build/) to create the Go application binary, and then attach it to a minimal base image. The Go version used is `1.22`, though it should work for most Go versions (not tested). You'll have to tweak the Dockerfile to `COPY` any static files required by the application, to be copied to the final image.
There are 4 Dockerfiles provided
1. [Debian](https://www.debian.org/) slim based
2. [Alpine](https://alpinelinux.org/) based
3. [BusyBox](https://www.busybox.net/) based
4. [Scratch](https://hub.docker.com/_/scratch) (no base OS layer)It's important that you understand [Go build flags](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies) to build a functioning binary for your application. Not all apps will work with build configuration provided in the Dockerfiles.
## How to build the example
```bash
$ docker build -t webgo-helloworld-alpine -f Dockerfile-alpine ./example$ docker build -t webgo-helloworld-debian -f Dockerfile-debian ./example
$ docker build -t webgo-helloworld-busybox -f Dockerfile-busybox ./example
$ docker build -t webgo-helloworld-scratch -f Dockerfile-scratch ./example
```## How to run?
```bash
$ docker run -p 8080:8080 --rm -ti webgo-helloworld-alpine
$ docker run -p 8080:8080 --rm -ti webgo-helloworld-debian
$ docker run -p 8080:8080 --rm -ti webgo-helloworld-busybox
$ docker run -p 8080:8080 --rm -ti webgo-helloworld-scratch
```## The gopher
The gopher used here was created using [Gopherize.me](https://gopherize.me/). The expert Docker gopher tells us how to build production ready, secure, Docker images for Go applications!