Docker

kratos-layout 中默认提供了用于构建程序的 Dockerfile 文件,文件中采用多阶段构建,以获得最小体积的容器镜像。

脚本内容

  1. FROM golang:1.15 AS builder
  2. COPY . /src
  3. WORKDIR /src
  4. RUN GOPROXY=https://goproxy.cn make build
  5. FROM debian:stable-slim
  6. RUN apt-get update && apt-get install -y --no-install-recommends \
  7. ca-certificates \
  8. netbase \
  9. && rm -rf /var/lib/apt/lists/ \
  10. && apt-get autoremove -y && apt-get autoclean -y
  11. COPY --from=builder /src/bin /app
  12. WORKDIR /app
  13. EXPOSE 8000
  14. EXPOSE 9000
  15. VOLUME /data/conf
  16. CMD ["./server", "-conf", "/data/conf"]

构建镜像

  1. docker build -t <your-docker-image-name> .

创建容器并运行

  1. docker run --rm -p 8000:8000 -p 9000:9000 -v </path/to/your/configs>:/data/conf <your-docker-image-name>