docker配置
mkdir -p dtm etcd etcd-manage golang grafana jaeger mysql mysql-manage prometheus redis redis-manage
配置dockerfile
echo "FROM mysql:5.7" > mysql/Dockerfile && \
echo "FROM yedf/dtm" > dtm/Dockerfile && \
echo "FROM bitnami/etcd" > etcd/Dockerfile && \
echo "FROM redis:5.0" > redis/Dockerfile && \
echo "FROM evildecay/etcdkeeper" > etcd-manage/Dockerfile && \
echo "FROM phpmyadmin/phpmyadmin" > mysql-manage/Dockerfile && \
echo "FROM erikdubbelboer/phpredisadmin" > redis-manage/Dockerfile && \
echo "FROM bitnami/prometheus" > prometheus/Dockerfile && \
echo "FROM grafana/grafana" > grafana/Dockerfile && \
echo "FROM jaegertracing/all-in-one:1.28" > jaeger/Dockerfile
配置golang
cat <<EOF > golang/Dockerfile
FROM golang:1.18
LABEL maintainer="Ving <ving@nivin.cn>"
ENV GOPROXY https://goproxy.cn,direct
# 安装必要的软件包和依赖包
USER root
RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/' /etc/apt/sources.list && \
sed -i 's/security.debian.org/mirrors.tuna.tsinghua.edu.cn/' /etc/apt/sources.list && \
sed -i 's/security-cdn.debian.org/mirrors.tuna.tsinghua.edu.cn/' /etc/apt/sources.list && \
apt-get update && \
apt-get upgrade -y && \
apt-get install -y --no-install-recommends \
curl \
zip \
unzip \
git \
vim
# 安装 goctl
USER root
RUN GOPROXY=https://goproxy.cn/,direct go install github.com/zeromicro/go-zero/tools/goctl@latest
# 安装 protoc
USER root
RUN curl -L -o /tmp/protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v3.19.1/protoc-3.19.1-linux-x86_64.zip && \
unzip -d /tmp/protoc /tmp/protoc.zip && \
mv /tmp/protoc/bin/protoc $GOPATH/bin
# 安装 protoc-gen-go
USER root
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
# 安装 protoc-gen-go-grpc
USER root
RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
# $GOPATH/bin添加到环境变量中
ENV PATH $GOPATH/bin:$PATH
# 清理垃圾
USER root
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
rm /var/log/lastlog /var/log/faillog
# 设置工作目录
WORKDIR /usr/src/code
EXPOSE 8000
EXPOSE 8001
EXPOSE 8002
EXPOSE 8003
EXPOSE 9000
EXPOSE 9001
EXPOSE 9002
EXPOSE 9003
EOF
.env
cat <<EOF > .env
# 设置时区
TZ=Asia/Shanghai
# 设置网络模式
NETWORKS_DRIVER=bridge
# PATHS ##########################################
# 宿主机上代码存放的目录路径
CODE_PATH_HOST=./code
# 宿主机上Mysql Reids数据存放的目录路径
DATA_PATH_HOST=./data
# MYSQL ##########################################
# Mysql 服务映射宿主机端口号,可在宿主机127.0.0.1:3306访问
MYSQL_PORT=3306
MYSQL_USERNAME=admin
MYSQL_PASSWORD=123456
MYSQL_ROOT_PASSWORD=123456
# Mysql 可视化管理用户名称,同 MYSQL_USERNAME
MYSQL_MANAGE_USERNAME=admin
# Mysql 可视化管理用户密码,同 MYSQL_PASSWORD
MYSQL_MANAGE_PASSWORD=123456
# Mysql 可视化管理ROOT用户密码,同 MYSQL_ROOT_PASSWORD
MYSQL_MANAGE_ROOT_PASSWORD=123456
# Mysql 服务地址
MYSQL_MANAGE_CONNECT_HOST=mysql
# Mysql 服务端口号
MYSQL_MANAGE_CONNECT_PORT=3306
# Mysql 可视化管理映射宿主机端口号,可在宿主机127.0.0.1:1000访问
MYSQL_MANAGE_PORT=1000
# REDIS ##########################################
# Redis 服务映射宿主机端口号,可在宿主机127.0.0.1:6379访问
REDIS_PORT=6379
# Redis 可视化管理用户名称
REDIS_MANAGE_USERNAME=admin
# Redis 可视化管理用户密码
REDIS_MANAGE_PASSWORD=123456
# Redis 服务地址
REDIS_MANAGE_CONNECT_HOST=redis
# Redis 服务端口号
REDIS_MANAGE_CONNECT_PORT=6379
# Redis 可视化管理映射宿主机端口号,可在宿主机127.0.0.1:2000访问
REDIS_MANAGE_PORT=2000
# ETCD ###########################################
# Etcd 服务映射宿主机端口号,可在宿主机127.0.0.1:2379访问
ETCD_PORT=2379
ETCD_MANAGE_PORT=7000
# PROMETHEUS #####################################
# Prometheus 服务映射宿主机端口号,可在宿主机127.0.0.1:3000访问
PROMETHEUS_PORT=3000
# GRAFANA ########################################
# Grafana 服务映射宿主机端口号,可在宿主机127.0.0.1:4000访问
GRAFANA_PORT=4000
# JAEGER #########################################
# Jaeger 服务映射宿主机端口号,可在宿主机127.0.0.1:5000访问
JAEGER_PORT=5000
# DTM #########################################
# DTM HTTP 协议端口号
DTM_HTTP_PORT=36789
# DTM gRPC 协议端口号
DTM_GRPC_PORT=36790
EOF
docker-compose.yml
version: '3.5'
# 网络配置
networks:
backend:
driver: ${NETWORKS_DRIVER}
# 服务容器配置
services:
golang: # 自定义容器名称
build:
context: ./golang # 指定构建使用的 Dockerfile 文件
environment: # 设置环境变量
- TZ=${TZ}
privileged: true
volumes: # 设置挂载目录
- ${CODE_PATH_HOST}:/usr/src/code # 引用 .env 配置中 CODE_PATH_HOST 变量,将宿主机上代码存放的目录挂载到容器中 /usr/src/code 目录
ports: # 设置端口映射
- "8000:8000"
- "8001:8001"
- "8002:8002"
- "8003:8003"
- "9000:9000"
- "9001:9001"
- "9002:9002"
- "9003:9003"
stdin_open: true # 打开标准输入,可以接受外部输入
tty: true
networks:
- backend
restart: always # 指定容器退出后的重启策略为始终重启
etcd: # 自定义容器名称
build:
context: ./etcd # 指定构建使用的 Dockerfile 文件
environment:
- TZ=${TZ}
- ALLOW_NONE_AUTHENTICATION=yes
- ETCD_ADVERTISE_CLIENT_URLS=http://etcd:2379
ports: # 设置端口映射
- "${ETCD_PORT}:2379"
networks:
- backend
restart: always
mysql:
build:
context: ./mysql
environment:
- TZ=${TZ}
- MYSQL_USER=${MYSQL_USERNAME} # 设置 Mysql 用户名称
- MYSQL_PASSWORD=${MYSQL_PASSWORD} # 设置 Mysql 用户密码
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} # 设置 Mysql root 用户密码
privileged: true
volumes:
- ${DATA_PATH_HOST}/mysql:/var/lib/mysql # 引用 .env 配置中 DATA_PATH_HOST 变量,将宿主机上存放 Mysql 数据的目录挂载到容器中 /var/lib/mysql 目录
ports:
- "${MYSQL_PORT}:3306" # 设置容器3306端口映射指定宿主机端口
networks:
- backend
restart: always
redis:
build:
context: ./redis
environment:
- TZ=${TZ}
privileged: true
volumes:
- ${DATA_PATH_HOST}/redis:/data # 引用 .env 配置中 DATA_PATH_HOST 变量,将宿主机上存放 Redis 数据的目录挂载到容器中 /data 目录
ports:
- "${REDIS_PORT}:6379" # 设置容器6379端口映射指定宿主机端口
networks:
- backend
restart: always
mysql-manage:
build:
context: ./mysql-manage
environment:
- TZ=${TZ}
- PMA_ARBITRARY=1
- MYSQL_USER=${MYSQL_MANAGE_USERNAME} # 设置连接的 Mysql 服务用户名称
- MYSQL_PASSWORD=${MYSQL_MANAGE_PASSWORD} # 设置连接的 Mysql 服务用户密码
- MYSQL_ROOT_PASSWORD=${MYSQL_MANAGE_ROOT_PASSWORD} # 设置连接的 Mysql 服务 root 用户密码
- PMA_HOST=${MYSQL_MANAGE_CONNECT_HOST} # 设置连接的 Mysql 服务 host,可以是 Mysql 服务容器的名称,也可以是 Mysql 服务容器的 ip 地址
- PMA_PORT=${MYSQL_MANAGE_CONNECT_PORT} # 设置连接的 Mysql 服务端口号
ports:
- "${MYSQL_MANAGE_PORT}:80" # 设置容器80端口映射指定宿主机端口,用于宿主机访问可视化web
depends_on: # 依赖容器
- mysql # 在 Mysql 服务容器启动后启动
networks:
- backend
restart: always
redis-manage:
build:
context: ./redis-manage
environment:
- TZ=${TZ}
- ADMIN_USER=${REDIS_MANAGE_USERNAME} # 设置 Redis 可视化管理的用户名称
- ADMIN_PASS=${REDIS_MANAGE_PASSWORD} # 设置 Redis 可视化管理的用户密码
- REDIS_1_HOST=${REDIS_MANAGE_CONNECT_HOST} # 设置连接的 Redis 服务 host,可以是 Redis 服务容器的名称,也可以是 Redis 服务容器的 ip 地址
- REDIS_1_PORT=${REDIS_MANAGE_CONNECT_PORT} # 设置连接的 Redis 服务端口号
ports:
- "${REDIS_MANAGE_PORT}:80" # 设置容器80端口映射指定宿主机端口,用于宿主机访问可视化web
depends_on: # 依赖容器
- redis # 在 Redis 服务容器启动后启动
networks:
- backend
restart: always
etcd-manage:
build:
context: ./etcd-manage
environment:
- TZ=${TZ}
ports:
- "${ETCD_MANAGE_PORT}:8080" # 设置容器8080端口映射指定宿主机端口,用于宿主机访问可视化web
depends_on: # 依赖容器
- etcd # 在 etcd 服务容器启动后启动
networks:
- backend
restart: always
prometheus:
build:
context: ./prometheus
environment:
- TZ=${TZ}
privileged: true
volumes:
- ./prometheus/prometheus.yml:/opt/bitnami/prometheus/conf/prometheus.yml # 将 prometheus 配置文件挂载到容器里
ports:
- "${PROMETHEUS_PORT}:9090" # 设置容器9090端口映射指定宿主机端口,用于宿主机访问可视化web
networks:
- backend
restart: always
grafana:
build:
context: ./grafana
environment:
- TZ=${TZ}
ports:
- "${GRAFANA_PORT}:3000" # 设置容器3000端口映射指定宿主机端口,用于宿主机访问可视化web
networks:
- backend
restart: always
jaeger:
build:
context: ./jaeger
environment:
- TZ=${TZ}
ports:
- ":16686" # 设置容器16686端口映射指定宿主机端口,用于宿主机访问可视化web
networks:
- backend
restart: always
dtm:
build:
context: ./dtm
environment:
- TZ=${TZ}
entrypoint:
- "/app/dtm/dtm"
- "-c=/app/dtm/configs/config.yaml"
privileged: true
volumes:
- ./dtm/config.yml:/app/dtm/configs/config.yaml # 将 dtm 配置文件挂载到容器里
ports:
- "${DTM_HTTP_PORT}:36789"
- "${DTM_GRPC_PORT}:36790"
networks:
- backend
restart: always
安装docker-compose命令
curl -L “https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-
(
u
n
a
m
e
−
s
)
−
(uname -s)-
(uname−s)−(uname -m)” -o /usr/local/bin/docker-compose
wget https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-$(uname -s)-$(uname -m)
&& mv docker-compose-$(uname -s)-$(uname -m) /usr/local/bin/docker-compose && chmod 777 /usr/local/bin/docker-compose
启动
docker-compose up -d
networks.backend.driver must be a string
yam 配置问题缺少${} 变量
watch -n 1 ‘docker images | grep gonivinck’
启动部分docker 状态create?
https://juejin.cn/post/7036010137408143373