以下golang程序会输出接收到的rquest header
package main
import (
"log"
"net/http"
handler "lizhe-auth/internal/handler"
)
func main() {
http.HandleFunc("/auth", handler.WithArgHandler)
log.Println("server started on 3080")
http.ListenAndServe(":"+"3080", nil)
}
package handler
import (
"log"
"net/http"
)
func WithArgHandler(writer http.ResponseWriter, request *http.Request) {
log.Println(request.Header)
}
构建Dockerfile
FROM golang:alpine as golang
RUN mkdir -p /root/auth
RUN mkdir -p /root/auth/output
COPY ./ /root/auth
WORKDIR /root/auth/output
RUN go build /root/auth/cmd/main.go
FROM alpine as alpine
RUN mkdir -p /root/auth
COPY --from=golang --chown=root:root /root/auth/output /root/auth
CMD /root/auth/main
然后build镜像
docker build -t libaibai/lizhe-auth:v0.1 .
docker run -i -t --name test -p 3080:3080 libaibai/lizhe-auth:v0.1