Im having problem building docker for golang api

I’m new to docker.

I’m trying to implement RESTfull api in go using echo server. My code works fine when I run main.go but i cant run it using docker.

this is my echo server:

r := router.Router()
r.Logger.Fatal(r.Start("localhost:8080"))

and this is my Dockerfile:

FROM golang:latest AS build

ENV GO111MODULE=on 
    CGO_ENABLED=1

#Maintainer info
LABEL maintainer="Saman Hoseini"

WORKDIR /app

COPY go.mod .
COPY go.sum .

RUN go mod download

COPY . .

RUN go build -o main .

#this step is for CGO libraries
RUN ldd main | tr -s '[:blank:]' 'n' | grep '^/' | 
    xargs -I % sh -c 'mkdir -p $(dirname ./%); cp % ./%;'
RUN mkdir -p lib64 && cp /lib64/ld-linux-x86-64.so.2 lib64/

#Second stage of build
FROM alpine:latest
RUN apk update && apk --no-cache add ca-certificates 
    sqlite

COPY --from=build /app ./

EXPOSE 8080

ENTRYPOINT ["./main"]

After build when i run the container i face curl failure:

$ docker run -d -p 8080:8080 my-docker

$ curl http://localhost:8080

curl: (56) Recv failure: Connection reset by peer

how can i fix this problem ?

Source: StackOverflow