Docker container has not set GOPATH correctly

  docker, go

I have a problem when I try to run my app in a Docker container. It is running fine with a simple go run main.go, but whenever I build an image and I run the docker container, I got the error of panic: html/template: pattern matches no files: *.html, so I guess GOPATH is not properly set in the docker container (tho I use this same docker file from other projects and I don’t have any problems). I am a little lost here, since this method I been using already for a while without problems.

I am using gin as a framework for develop.

The docker file is:

FROM golang:alpine as builder

RUN apk update && apk add git && apk add ca-certificates 
# For email certificate
RUN apk add -U --no-cache ca-certificates


RUN go get -d -v $GOPATH/src/

# For Cloud Server
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-w -s" -o /go/bin/advanced-performance $GOPATH/src/

FROM scratch
COPY --from=builder /go/bin/advanced-performance /advanced-performance
COPY --from=builder /go/src/ /go/src/

# For email certificate
VOLUME /etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

EXPOSE 8050/tcp

ENTRYPOINT ["/advanced-performance"]

Main function is:

package main

import (

    i18n ""

func main() {
    // We create the instance for Gin
    r := gin.Default()

    /* Internationalization for showing the right language to match the browser's  default settings
    bundle := i18n.NewBundle(

    // Tell Gin to use our middleware. This means that in every single request (GET, POST...), the call to i18n will be executed

    // Path to the static files. /static is rendered in the HTML and /media is the link to the path to the  images, svg, css.. the static files
    r.StaticFS("/static", http.Dir("media"))

    // Path to the HTML templates. * is a wildcard

    // Redirects when users introduces a wrong URL

    // This get executed when the users gets into our website in the home domain ("/")
    r.GET("/", renderHome)
    r.POST("/", getForm)
    // Listen and serve on (for windows "localhost:8080")


The full project can be found in, is a simple website rendering with i18n and a POST form-handler

Source: Docker Questions