bnkamalesh / golang-dockerfile

Dockerfiles for building Go application images

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

docker gopher

Go Dockerfile v0.1.6

Dockerfiles to build Docker images for your Go app. It makes use of Docker's multi-stage build feature 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 slim based
  2. Alpine based
  3. BusyBox based
  4. Scratch (no base OS layer)

It's important that you understand Go build flags 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

$ 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?

$ 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. The expert Docker gopher tells us how to build production ready, secure, Docker images for Go applications!

About

Dockerfiles for building Go application images

License:MIT License


Languages

Language:Go 100.0%