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"