Docker - Build an application to an image

发布时间 2023-12-08 21:44:55作者: ZhangZhihuiAAA

Dockerfile:

# Build stage
FROM golang:1.21.5-alpine3.18 AS builder
WORKDIR /app 
COPY . .
RUN go env -w GOPROXY=https://goproxy.io,direct
RUN go build -o main main.go

# Run stage
FROM alpine:3.18
WORKDIR /app
COPY --from=builder /app/main .

EXPOSE 8080
CMD [ "/app/main"]

 

zzh@ZZHPC:/zdata/Github/zimplebank$ docker build -t zimplebank:latest .

 

zzh@ZZHPC:/zdata/Github/zimplebank$ docker images
REPOSITORY   TAG       IMAGE ID       CREATED              SIZE
zimplebank   latest    1ab108eea809   About a minute ago   25.4MB