前两天因为要在服务器上部署MySQL方便我进行项目的开发,但是发现我服务器上的Docker容器有点多,于是想到了之前看见的Docker Compose的多容器管理工具
思路
Docker Compose是一个很易于使用的多容器管理方案 基本思路如下
- 编写
docker-compose.yml
- 执行
docker compose -f /path/to/docker-compose.yml up -d
docker-compose.yml
version: '3.8' services: # mysql容器 cunoe-mysql: image: mysql:5.7 container_name: cunoe-mysql restart: always environment: - MYSQL_USER=cunoe - MYSQL_PASSWORD=<Password> - MYSQL_ROOT_PASSWORD=<RootPassword> - MYSQL_ALLOW_EMPTY_PASSWORD=no - MYSQL_DATABASE=rankv1 ports: - 3306:3306 networks: - cunoenet # phpmyadmin容器 phpmyadmin: image: phpmyadmin/phpmyadmin:latest container_name: cunoe-phpmyadmin depends_on: - cunoe-mysql ports: - 3000:80 environment: - MYSQL_USER=root - MYSQL_PASSWORD=<Password> - MYSQL_ROOT_PASSWORD=<RootPassword> - PMA_HOST=cunoe-mysql networks: - cunoenet # portainer容器 portainer: image: portainer/portainer-ce:2.0.1 container_name: cunoe-portainer restart: always ports: - 3001:9000 volumes: - /var/run/docker.sock:/var/run/docker.sock networks: - cunoenet # frps容器 frps: image: snowdreamtech/frps:latest container_name: cunoe-frps restart: always network_mode: host volumes: - /etc/frp/frps.ini:/etc/frp/frps.ini # Aria2服务 aria2: image: p3terx/aria2-pro container_name: cunoe-aria2 restart: unless-stopped network_mode: host logging: driver: json-file options: max-size: 1m environment: - PUID=65534 - PGID=65534 - UMASK_SET=022 - RPC_SECRET=<TOKEN> - RPC_PORT=6800 - LISTEN_PORT=6888 - DISK_CACHE=64M - IPV6_MODE=false - UPDATE_TRACKERS=true - CUSTOM_TRACKER_URL=<Tracker URL> - TZ=Asia/Shanghai volumes: - /etc/aria2/config:/config - /home/webdav:/downloads # AriaNg服务 AriaNg: container_name: cunoe-ariang image: p3terx/ariang command: --port 3002 network_mode: host restart: unless-stopped logging: driver: json-file options: max-size: 1m # webdav服务 webdav: image: ugeek/webdav:amd64 container_name: cunoe-webdav volumes: - /home/webdav:/media environment: - USERNAME=admin - PASSWORD=password - TZ=Asia/Shanghai - UDI=1000 - GID=1000 ports: - 3003:80 # 创建网络 networks: cunoenet: driver: bridge
实质上跟一行一行的docker run
nginx.conf
通过Nginx进行端口的反向代理即可完成部署
``````more`````` # phpmyadmin location ^~ /db/ { proxy_pass http://127.0.0.1:3000/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } # portainer location ^~ /docker/ { proxy_pass http://127.0.0.1:3001/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } # Ariang location ^~ /ariang/ { proxy_pass http://127.0.0.1:3002/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } # Webdav location ^~ / { proxy_pass http://127.0.0.1:3003; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /jsonrpc { proxy_redirect off; proxy_pass http://127.0.0.1:6800/jsonrpc; #配置为你Aria2的RPC即可 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } ``````more``````