LiuYuan's Blog
This is LiuYuan's Blog
Toggle navigation
LiuYuan's Blog
Home
Docker相关
MySQL相关
Ansible相关
维护脚本相关
Windows系统脚本
Python相关
Nginx相关
About Me
Archives
Tags
Dcokerfile/docker-compose
2024-06-19 15:25:39
33
0
0
admin
1. golang程序常见docker 直接运行 #设置基础镜像来源 FROM golang:1.17-alpine #设置时区 ENV TZ=Asia/Shanghai RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone #设置代理 RUN go env -w GOPROXY=https://goproxy.cn,direct #设置工作目录 WORKDIR /data/ #复制代码 COPY data/. . #安装环境组件 RUN go mod tidy -compat=1.17 #启动主程序 #RUN go run main.go #设置端口 EXPOSE 8080 #设置启动命令 CMD ["go","run","main.go"] 构建二进制运行 # 构建成二进制文件 FROM golang:1.17-alpine # 开启 Go Module RUN go env -w GO111MODULE=on RUN go env -w GOPROXY=https://goproxy.cn,direct WORKDIR /data/ COPY . . RUN CGO_ENABLED=0 GOOS=linux go build -a -o app.api . # 配置运行环境 FROM alpine:3 # 设置为中国时区 # 设置系统根证书 RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories RUN apk --no-cache add tzdata && \ apk add ca-certificates && \ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo "Asia/Shanghai" > /etc/timezone ENV TZ Asia/Shanghai WORKDIR /data/ COPY --from=0 /data/app.api . ## 本地测试用,直接用当前的yaml文件 COPY --from=0 /data/conf.yaml . CMD ["./app.api"] docker-compose.yml services: lls_dgame_go: image: lls_dgame_go container_name: lls_dgame_go build: context: . dockerfile: Dockerfile ports: - "18090:8080" restart: always networks: - mynet volumes: - /docker/conf.yaml:/data/conf.yaml # 配置文件 - /docker/logs:/data/logs # 日志记录 - /docker/question.xlsx:/data/question.xlsx # 问题excel networks: mynet: external: true MySQL docker-compose.yml version: '3' services: mysql-db: container_name: mysql # 指定容器的名称 image: mysql:8.0.20 # 指定镜像和版本 ports: - "3306:3306" environment: MYSQL_ROOT_PASSWORD: luckyxp84711566 TZ: Asia/Shanghai command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --explicit_defaults_for_timestamp=true --lower_case_table_names=1 volumes: - /data/mysql:/var/lib/mysql # 挂载数据目录 - /docker/mysql/conf:/etc/mysql # 配置文件目录 restart: always networks: mynet: external: true
Pre:
MySQL安装
Next: No Post
0
likes
33
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Footer
Table of content