本文以一个简单的Go应用Demo来演示Kubernetes应用部署的完整流程
Dockerfile多阶段构建
[root@docker github]# git clone https://gitee.com/yxydde/http-dump.git [root@docker github]# cd http-dump/ [root@docker http-dump]# cat Dockerfile FROM golang:1.19.0 AS builder WORKDIR /app COPY main.go . COPY go.mod . RUN go build -a -o http-dump . # 这里使用多阶段构建,只复制编译结果到最终镜像,可以明显减小镜像大小 FROM debian:stable-slim WORKDIR /app/ COPY --from=0 /app/http-dump . EXPOSE 8080 CMD ["./http-dump"]
结合 12.Harbor构建私有镜像仓库 ,构建镜像并推送的私有仓库
[root@docker http-dump]# docker build -t harbor.example.io/apps/http-dump . Sending build context to Docker daemon 77.31kB Step 1/10 : FROM golang:1.19.0 AS builder ---> 505a511fa01d