Ping-Pong Webserver 구현
Working Directory : go-docker
사용 웹프레임워크 : gin-gonic
package main
import (
"github.com/gin-gonic/gin"
)
func main() {
//gin.SetMode(gin.ReleaseMode) 릴리즈 모드 활성화 하고 싶으면 주석 해제
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.Run(":3000") // port
}
go mod init go-docker
Working directory에 Dockerfile 생성
FROM golang:alpine AS builder
ENV GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64
WORKDIR /build
COPY go.mod go.sum main.go ./
RUN go mod download
RUN go build -o main .
WORKDIR /dist
RUN cp /build/main .
FROM scratch
COPY --from=builder /dist/main .
ENTRYPOINT ["/main"]
docker build . -t go-dock
docker run -p 3000:3000 go-dock
curl http://localhost:3000/ping
Using Go Module
docker.com/blog
😊