Example Dockerfile for running a go application inside docker container.

Base Image for Golang

We need a base image on which we will build our application. You can specify the version you want. In the example I used alpine version which are very lightweight.

To use full and latest version use latest instead of 1.13.4-alpine3.10 :

FROM golang:latest

For more options check official images for golang applications https://hub.docker.com/_/golang/

Running the docker file

docker build -t my-go-app .
docker run -p 8080:8080 -it my-go-app

Running it in background use:

docker run -d -p 8080:8080 my-go-app