测试容器编译

This commit is contained in:
suguo.yao 2023-05-10 11:09:44 +08:00
parent b0a8c9e2c2
commit bc8512edcf
4 changed files with 44 additions and 0 deletions

1
.gitignore vendored
View File

@ -15,3 +15,4 @@
# Dependency directories (remove the comment below to include it) # Dependency directories (remove the comment below to include it)
# vendor/ # vendor/
hello

27
Dockerfile Normal file
View File

@ -0,0 +1,27 @@
FROM golang:1.18 as builder
ENV GO111MODULE=on \
GOPROXY=https://goproxy.io
COPY . /app
WORKDIR /app
RUN go get && go build -ldflags="-s -w" -installsuffix cgo -o hello
FROM alpine:latest
ENV TZ=Asia/Shanghai \
LANG=C.UTF-8 \
APP_DIR=/app
COPY --from=builder /app/hello ${APP_DIR}/hello
WORKDIR ${APP_DIR}
RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime \
&& echo ${TZ} > /etc/timezone \
&& chmod +x hello
# EXPOSE 5678
CMD ["./hello"]

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module myschools.me/suguo/hello
go 1.20

13
main.go Normal file
View File

@ -0,0 +1,13 @@
package main
import (
"fmt"
"time"
)
func main() {
for {
fmt.Println(time.Now().Format("2006-01-02 15:04:05"), "hello world.")
time.Sleep(time.Minute)
}
}