GIn+Docker+docer-compose

FROM docker.io/golang:1.15.14 as builder
COPY .  /
WORKDIR /Initial
ENV GO111MODULE=on \
GOPROXY=https://goproxy.cn,direct
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o app main.go
RUN mkdir publish && cp app publish && \
    cp -r docs publish
FROM alpine
WORKDIR /Initial
COPY --from=builder /Initial/app .
ENV GIN_MODE=release \
PORT=8880
EXPOSE 8880
ENTRYPOINT ["./app"]

因为 go的原生镜像比较大,所以采用了分布构建,ps:记得用新版本的docker。

docker-compose:

version: '3'
services:

  mysql:
    image: mysql:5.7.23
    restart: always
    command: --default-authentication-plugin=mysql_native_password
    ports:
      - "3306:3306"
    volumes:
      - /XX/mysql/data/:/var/lib/mysql
      - /XX/mysql/sql:/docker-entrypoint-initdb.d
    environment:
      - "MYSQL_ROOT_PASSWORD=123456"
      - "MYSQL_ROOT_HOST=%"
      - "MYSQL_DATABASE=more"
      - "TZ=Asia/Shanghai"

  web:
    image: app:latest
    links:
      - mysql
    restart: on-failure
    ports:
      - "8880:8880"

  

上一篇:最新整理:Google/网易/腾讯/百度/华为面经(25个专题 1W字答案解析)


下一篇:goland 2021.1:给go项目改名