Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

打包成 Docker镜像后如何运行 HTTP服务 和 Websocket、TCP 服务 #16

Open
LinLiang66 opened this issue Apr 27, 2024 · 0 comments

Comments

@LinLiang66
Copy link

FROM golang:1.21.5-alpine

WORKDIR /go/src/go_chat
COPY . .

为我们的镜像设置必要的环境变量

ENV GO111MODULE=on
CGO_ENABLED=0
GOOS=linux
GOARCH=amd64
GOPROXY="https://goproxy.cn,direct"
RUN echo http://mirrors.aliyun.com/alpine/v3.10/community/ > /etc/apk/repositories
&& echo http://mirrors.aliyun.com/alpine/v3.10/main/ >> /etc/apk/repositories
&& apk add tzdata
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
&& echo 'Asia/Shanghai' >/etc/timezone
RUN go build -o go_chat .

CMD ["./go_chat"]

构造镜像后 运行 docker run -d -v /root/chat/go-chat:/app -p 9503:9503 --name go_chat_http-1 --restart=always go_chat http 无效 末尾的 http是要启动的服务类别

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant