Make your own service into a docker image

Purpose

The previous article introduced how to install k8s on two Tencent Clouds. This article will create a docker image on the k8s master (Tencent Cloud xxxx), and run the hecheng_be service in docker to facilitate subsequent deployment of this docker to k8s

Environment construction

1. Install git

yum install -y git
复制代码

image.png

2. Pull the code from github to the specified directory

cd /home/workspaces/go/src/hecheng_be

git clone https://github.com/XXX/hecheng_be.git
复制代码

Write 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 git config --global url.https://[email protected]/treelab/.insteadOf https://github.com/treelab/

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/[email protected]
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. Make a docker image

docker build -f Dockerfile -t docker_repo_usename/hecheng_be_docker_image .
复制代码

Note that the name here must be docker_repo_usename/iamge_name, otherwise it cannot be pushed to the remote end. View after production is complete

docker image ls
复制代码

image.png

4. Push the created mirror to the far end

Log in

docker login
复制代码

push to the far end

docker push docker_repo_usename/hecheng_be_docker_image
复制代码

The next article will introduce running this image in k8s

reference

[1] dockerfile makes docker image

Guess you like

Origin juejin.im/post/7087511347529220133