目的
上一篇文章介绍了如何在两台腾讯云上安装k8s,本文将制作docker镜像,在docker中运行hecheng_be服务,并且将镜像推到远端,方便后续将此docker image 部署到k8s
环境搭建
1.安装git
yum install -y git
2.从github拉取代码到指定目录
cd /home/workspaces/go/src/hecheng_be
git clone https://github.com/XXX/hecheng_be.git
写Dockfile
FROM golang:1.17.5
WORKDIR /app
# 使用阿里源替换 debian 源
RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list
RUN apt-get update && \
apt-get install unzip && \
apt-get install libprotobuf-dev -y
ENV HOME=/root
COPY go.mod go.sum ./
ENV GO111MODULE=on
ENV GOPROXY=https://goproxy.cn
RUN go install github.com/cosmtrek/air@latest
RUN go install github.com/go-delve/delve/cmd/dlv@latest
RUN go install github.com/golang/mock/mockgen@v1.6.0
RUN go install github.com/vektra/mockery/v2/.../
ENV PATH="${PATH}:${HOME}/.local/bin"
RUN go mod download
COPY . .
EXPOSE 50051 8080 2345
CMD ["air", "-c", ".air.toml"]
3.制作docker镜像
docker build -f Dockerfile -t docker_repo_usename/hecheng_be_docker_image .
注意,这里的名字一定要是docker_repo_usename/iamge_name,否则不能推到远端。制作完成后查看
docker image ls
4.将制作好的镜像推到远端
登录
docker login
推到远端
docker push docker_repo_usename/hecheng_be_docker_image
下篇文章将介绍把这个镜像在k8s中运行