Deploying V2Ray with Docker
This article was translated by AI (LLM). There may be errors or inaccuracies. For the original content, please refer to the original version.
There are limited Chinese resources on Docker deployment for V2Ray. Here’s some reference material.
Installing Docker Service
- Install Docker using package manager (using pacman as example):
sudo pacman -S docker - Obtain Docker operation permissions (refer to Docker Wiki):
sudo groupadd docker sudo usermod -aG docker $USER - Start Docker service:
sudo systemctl enable docker sudo systemctl start docker
Installing V2Ray (Docker Container)
Note: v2ray/official is deprecated.
- Download V2Ray container:
docker pull v2fly/v2fly-core
V2Ray Configuration File
Recommended location for V2Ray config file: /home/$USER/.config/v2ray/config.json (can be elsewhere)
- V2Ray inbound rules should point to 0.0.0.0 (as shown below), with default port set to 1080
"inbounds": [
{
"port": 1080,
"listen": "0.0.0.0",
"protocol": "socks",
"sniffing": {
"enabled": true,
"destOverride": [
"http",
"tls"
]
}
}
],
- V2Ray Multi-protocol Proxy
V2Ray supports multiple inbound protocols. References:
Example with HTTP and SOCKS5:
"inbounds": [
{
"port": 1080,
"listen": "0.0.0.0",
"protocol": "socks",
"sniffing": {
"enabled": true,
"destOverride": [
"http",
"tls"
]
}
},
{
"listen": "0.0.0.0",
"port": 8118,
"protocol": "http",
"settings": {
"timeout": 0,
"allowTransparent": false,
"userLevel": 0
}
}
],
Running V2Ray Container
- Single protocol single port
docker run -dit -d \
--restart unless-stopped \ # Auto-start container on boot
--name v2ray \ # Set container name
-v /home/xz/.config/v2ray/config.json:/etc/v2ray/config.json \ # File mapping
-p 127.0.0.1:1080:1080 \ # Network port mapping to localhost, can map to other IP if needed
v2fly/v2fly-core \
v2ray -config=/etc/v2ray/config.json
- Multi-protocol multi-port (example with HTTP and SOCKS5 above)
docker run -dit -d \
--restart unless-stopped \
--name v2ray \
-v /home/xz/.config/v2ray/config.json:/etc/v2ray/config.json \
-p 127.0.0.1:1080:1080 \
-p 127.0.0.1:8118:8118 \
v2fly/v2fly-core \
v2ray -config=/etc/v2ray/config.json
Installing Docker Container Auto-update Service (Optional)
- Install Watchtower:
docker pull v2tec/watchtower
- Run Watchtower
docker run -d \
--name watchtower \
-v /var/run/docker.sock:/var/run/docker.sock \
v2tec/watchtower