Set up openvpn through docker-compose
Step0:
下載image映像檔
Step1:安裝部署
撰寫docker-compose.yml文件
version: '2.3'
services:
openvpn-service:
image: <映像檔路徑>
container_name: openvpn-service
cap_add:
- NET_ADMIN
restart: always
mem_limit: 64M
logging:
driver: "json-file"
options:
max-size: "1m"
max-file: "3"
ports:
- "11194:1194/udp"
networks:
- openvpn-service
volumes:
- ./data:/etc/openvpn
networks:
openvpn-service:
name: openvpn-service-network
driver: bridge
Step2:匯出憑證
# 取一個客戶端名稱
export CLIENTNAME="env-uat"
# 建立一個客戶端的憑證檔案
docker-compose run --rm ovpn easyrsa build-client-full "$CLIENTNAME" nopass
# 將客戶端的憑證檔案匯出
docker-compose run --rm ovpn ovpn_getclient "$CLIENTNAME" > "$CLIENTNAME.ovpn"
排錯步驟1:
- ERROR: Linux route delete command failed: external program exited with error status: 2
- 編輯openvpn.conf
#註解下面這兩行之後重啟即可
#user nobody
#group nogroup
comp-lzo no
compress lz4-v2
cipher AES-256-CBC
explicit-exit-notify 1
duplicate-cn
max-clients 10
client-to-client
排錯步驟2:
若只是ip發生異動,不需重新匯出憑證
#記事本打開原本的.open憑證檔案
client
nobind
dev tun
remote-cert-tls server
#找到這句進行修改
remote <修改成你的hostname/ip> 11194 udp
保存之後重新匯入.opvn文件至openvpn app即可