Frp也支持Docker部署,通过简单的编写docker-compose文件,实现快速部署内网穿透服务。
需求:需要被穿透的内网服务器,有公网IP的服务器一台,正常接入互联网,内网机器和服务器操作系统均为Ubuntu 20.04 Server或CentOS 7.9
服务端配置(公网服务器)
服务端安装Docker及Docker-Compose
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
| curl -sSL https://get.daocloud.io/docker | sh
yum update -y yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo yum -y install yum-utils yum list docker-ce --showduplicates | sort -r yum install -y docker-ce
systemctl start docker systemctl enable docker
wget https://cloud.18db.top/d/aliyunpan/get/docker-compose/docker-compose-linux-x86_64-v2.17.0 -O /usr/local/bin/docker-compose
wget https://cloud.18db.top/d/aliyunpan/get/docker-compose/docker-compose-linux-x86_64-v2.17.3 -O /usr/local/bin/docker-compose
wget https://cloud.18db.top/d/aliyunpan/get/docker-compose/docker-compose-linux-x86_64-v2.16.0 -O /usr/local/bin/docker-compose
wget https://cloud.18db.top/d/aliyunpan/get/docker-compose/docker-compose-Linux-x86_64-v1.29.2 -O /usr/local/bin/docker-compose
curl -SL https://github.com/docker/compose/releases/download/v2.17.2/docker-compose-linux-x86_64 -O /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
|
创建服务端FRP目录
1 2 3
| mkdir /root/docker-compose-data/frp
cd /root/docker-compose-data/frp
|
创建 Docker-compose.yml和frps.ini文件
1 2
| vim docker-compose.yml touch frps.ini
|
配置Docker-compose.yml文件
1 2 3 4 5 6 7 8 9
| version: '3.3' services: frps: restart: always network_mode: host volumes: - './frps.ini:/etc/frp/frps.ini' container_name: frps image: snowdreamtech/frps
|
配置frps.ini
1 2 3 4 5 6 7 8 9
| [common] bind_port=5400
dashboard_user=root dashboard_pwd=12345 dashboard_port=9527
token = pwd12345
|
在/root/docker-compose-data/frp下,启动容器
1 2 3
| docker-compose up -d
docker ps
|
注意:记得把服务端的防火墙端口打开,否则FRP服务可能会无法工作
客户端配置(内网服务器)
Docker和Docker-compose安装可以参考服务端的方法,FRP目录创建也同上面一样。
关键在于docker-compose.yml和frpc.ini的配置
创建客户端目录
1 2 3 4
| cd cd /root/docker-compose-data/frp
vim docker-compose.yml touch frpc.ini
|
配置docker-compose.yml
注意:这里不是”frps”是”frpc”
1 2 3 4 5 6 7 8 9
| version: '3.3' services: frpc: restart: always network_mode: host volumes: - './frpc.ini:/etc/frp/frpc.ini' container_name: frpc image: snowdreamtech/frpc
|
配置frpc.ini
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
| [common] server_addr= 127.0.0.1 server_port= 5400 token = pwd123
[jellyfin] type = tcp local_ip = 127.0.0.1 local_port = 8096 remote_port = 6001
|
启动容器,在/root/docker-compose-data/frp下
测试访问
1 2 3
| http://服务端ip地址:你设置的remote_port
https://web.com
|