May 24, 2024, 6:56 a.m. | Yanuar Arifin

DEV Community dev.to

This post will explain how I create Dockerfile and docker-compose.yml for golang development. The full code can be seen here


This code for Dockerfile


FROM golang:1.22 

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY . ./

RUN CGO_ENABLED=0 GOOS=linux go build -o /go-market-warehouse-api ./cmd/main.go

EXPOSE 8000

CMD [ "/go-market-warehouse-api" ]


FROM golang:1.22 is basing the image to current newest golang version available


WORKDIR /app tell docker to create and make this /app directory as the current directory …

api app application build code compose copy create development docker docker-compose download go golang linux market sum tutorial warehouse webdev will

AI Focused Biochemistry Postdoctoral Fellow

@ Lawrence Berkeley National Lab | Berkeley, CA

Senior Data Engineer

@ Displate | Warsaw

Solutions Architect

@ PwC | Bucharest - 1A Poligrafiei Boulevard

Research Fellow (Social and Cognition Factors, CLIC)

@ Nanyang Technological University | NTU Main Campus, Singapore

Research Aide - Research Aide I - Department of Psychology

@ Cornell University | Ithaca (Main Campus)

Technical Architect - SMB/Desk

@ Salesforce | Ireland - Dublin