docker-compose一键部署FRP、YAPI

创建yml文件

  • docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

version: '3.6'
# networks:
#   nginx_bridge:
#     driver: bridge
networks: ##定义网络组
  nginx-group: ## 网络组名称
    driver: bridge ## 网络的模式
    ipam: ## 配置网络
      driver: default
      config:
        - subnet: 192.168.5.0/10 ## ip地址网络 这里宿主机一般会是该网段的 192.168.5.1,所以不要设置自网段为1
services:
  yapi:
    build:
      context: ./yapi/
      dockerfile: Dockerfile
    image: yapi
    container_name: yapi
    restart: always
    # 第一次启动使用
    # command: "yapi server"
    # 之后使用下面的命令
    command: "node lancema-yapi/vendors/server/app.js"
    volumes: 
        - $PWD/yapi/lancema-yapi:/lancema-yapi
    ports: 
      - 3000:3000
    depends_on: 
      - mongo
    networks:
      nginx-group:
        ipv4_address: 192.168.5.5
  frps:
    image: snowdreamtech/frps:0.34.0
    container_name: frps
    restart: always
    # expose:
    #   - 8866
    ports:
      - 7000:7000
      - 8866:8866
    volumes:
      - $PWD/frps/frps/frps.ini:/etc/frp/frps.ini
    #network_mode: host
    networks:
      nginx-group:
        ipv4_address: 192.168.5.3
  mongo:
    image: mongo:4
    container_name: mongo-4
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: Mmg224330.?
      MONGO_INITDB_DATABASE: yapi
    volumes: 
        - $PWD/yapi/mongo-conf:/docker-entrypoint-initdb.d
        - $PWD/yapi/mongo/etc:/etc/mongo
        - $PWD/yapi/mongo/data/db:/data/db
    ports: 
        - 27017:27017
    healthcheck:
      test: ["CMD""netstat -anp | grep 27017"]
      interval: 2m
      timeout: 10s
      retries: 3
    networks:
      nginx-group:
        ipv4_address: 192.168.5.4
  nginx:
    container_name: nginx
    image: nginx:1.19.5
    ports:
      - 80:80
      - 443:443
    restart: always
    volumes:
      - $PWD/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
      - $PWD/nginx/conf/ssl:/etc/nginx/ssl
      - $PWD/nginx/conf/vhost:/etc/nginx/vhost
      - $PWD/nginx/conf/rewrite:/etc/nginx/rewrite
    networks:
      nginx-group:
        ipv4_address: 192.168.5.2

创建conf文件

  • frps.baidu.com.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
server {
    listen 80;
    listen [::]:80;
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    ssl_certificate ssl/frps.baidu.com.pem;
    ssl_certificate_key ssl/frps.baidu.com.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
    ssl_prefer_server_ciphers on;
    ssl_session_timeout 10m;
    ssl_session_cache builtin:1000 shared:SSL:10m;
    ssl_buffer_size 1400;
    add_header Strict-Transport-Security max-age=15768000;
    ssl_stapling on;
    ssl_stapling_verify on;
    server_name frps.baidu.com;
    # 
    #access_log /data/wwwlogs/frps.baidu.com_nginx.log combined;
    #index index.html index.htm;
    #root /data/www/frps;
    if ($ssl_protocol = "") { return 301 https://$host$request_uri# ; }
    if ($host != frps.baidu.com) {  return 301 $scheme://frps.baidu.com$request_uri# ;  }
    
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    location / {
        proxy_pass   http://frps:8866 ; #frps 代表docker-compose中配置的frp容器名
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
}

创建json文件

  • yapi/lancema-yapi/config.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
   "port""3000",
   "adminAccount""lancema@qq.com",
   "closeRegister":true,
   "versionNotify"true,
   "db": {
      "servername""192.168.1.1",
      "DATABASE""yapi",
      "port""27017",
      "user""yapi数据库用户名",
      "pass""yapi数据库密码"
   },
   "mail": {
      "enable"false,
      "host""smtp.163.com",
      "port"465,
      "from""***@163.com",
      "auth": {
         "user""***@163.com",
         "pass""*****"
      }
   }
}

文件目录结构

docker-compose一键部署FRP、YAPI-文件目录结构