Skip to content

V2Ray Docker Compose Configurations (Single Server, Relay and Upstream Servers, Websockets + TLS + CDN) with Shadowsocks, VMess, SOCKS, and HTTP Protocols

Notifications You must be signed in to change notification settings

miladrahimi/v2ray-docker-compose

Repository files navigation

V2Ray Docker Compose

This repository contains Docker Compose configurations for V2Ray, enabling users to bypass firewalls.

V2Ray is a proxy tool equipped with advanced functionalities and supports protocols such as Shadowsocks, VMess, VLess, and Trojan. Currently, V2Fly maintains V2Ray, while the original V2Ray is no longer active.

Table of contents

Server Configurations

V2Ray Single Server

The "V2Ray Single Server" configuration is the simplest way to get started with V2Ray. However, if your network or internet access is highly restricted, this configuration may not be effective.

For this configuration, a single server serves as the upstream. The flow of this solution is shown below.

Client <-> Upstream Server <-> Internet

To set up "V2Ray Single Server" using Docker Compose, follow the steps described below.

  1. Install Docker and Docker-compose (Official Documanetation).
  2. Run git clone https://github.com/miladrahimi/v2ray-docker-compose.git to download this repository.
  3. Run cd v2ray-docker-compose/v2ray-single-server to change the directory.
  4. Replace <SHADOWSOCKS-PASSWORD> in v2ray.json with a secure password like FR33DoM.
  5. If ufw is installed and enabled, run ufw allow 8000.
  6. Run docker compose up -d.
  7. Run ./clients.py to generate client configurations.
  8. (Optional) Run ./../utils/bbr.sh to setup BBR and speed up the server network.

The default configuration uses the Shadowsocks protocol, but you can manually add any other protocols supported by V2Ray to the configuration. For detailed information on available protocols, please refer to the official documentation. For ready-to-use configuration examples, visit the official configuration examples.

V2Ray Upstream and Relay Servers

The "V2Ray Upstream and Relay Servers" configuration is recommended for users with highly restricted network or internet access. When clients can't connect reliably to upstream servers, a relay server can help. The relay server must be accessible to clients and have a stable connection to upstream servers.

This configuration uses V2Ray on the upstream server, using the Shadowsocks protocol for communication with the relay server. The relay server provides Shadowsocks protocol for clients, in addition to SOCKS5 and HTTP Proxy protocols for the relay server's own use.

You will need two servers:

  • Upstream Server: A server with access to the free internet, likely located in a foreign data center.
  • Relay Server: A server that connects to the upstream server and is accessible to clients, ideally located in a datacenter within the same region as clients.

The flow of V2Ray Upsream and Relay Servers:

Client <-> Relay Server <-> Upstream Server <-> Internet

Step 1: Setup Upstream Server

  1. Install Docker and Docker-compose (Official Documanetation).
  2. Run git clone https://github.com/miladrahimi/v2ray-docker-compose.git to download this repository.
  3. Run cd v2ray-docker-compose/v2ray-upstream-server to change the directory.
  4. Replace <UPSTREAM-PASSWORD> in v2ray.json with a Shadowsocks password like FR33DoM.
  5. If ufw is installed and enabled, run ufw allow 8000.
  6. Run docker compose up -d.
  7. (Optional) Run ./../utils/bbr.sh to setup BBR and speed up the server network.

Step 2: Setup Relay Server

  1. Install Docker and Docker-compose (Official Documanetation).
  2. Run git clone https://github.com/miladrahimi/v2ray-docker-compose.git to download this repository.
  3. Run cd v2ray-docker-compose/v2ray-relay-server to change the directory.
  4. Replace the following variables in v2ray.json with appropriate values.
    • <RELAY-PASSWORD>: A password for Shadowsocks user like FR33DoM.
    • <UPSTREAM-IP>: The upstream server IP address (like 13.13.13.13).
    • <UPSTREAM-PASSWORD>: The Shadowsocks password from the upstream server in the previous step.
  5. If ufw is installed and enabled, run ufw allow 8000.
  6. Run docker compose up -d.
  7. Run ./clients.py to generate client configurations.
  8. (Optional) Run ./../utils/bbr.sh to setup BBR and speed up the server network.

V2Ray Behind CDN

The "V2Ray Behind CDN" configuration is recommended for users with highly restricted network or internet access, and when a relay server is not an option.

This configuration provides VMess protocol over Websockets + TLS + CDN (Read more) for users.

In this configuration, you need an upstream server and a domain integrated with a CDN service:

  • Upstream Server: A server with access to the free internet, likely located in a foreign data center.
  • CDN Service: A Content Delivery Network service like Cloudflare and ArvanCloud.

The flow of V2Ray Behind CDN:

Client <-> CDN <-> Upstream Server <-> Internet

Follow these steps to set up V2Ray, Caddy (Web server) and CDN:

  1. In the CDN panel, create an A record for the server IP with the proxy option disabled.
  2. Install Docker and Docker-compose (Official Documanetation).
  3. Run git clone https://github.com/miladrahimi/v2ray-docker-compose.git to download this repository.
  4. Run cd v2ray-docker-compose/v2ray-caddy-cdn to change the directory.
  5. Run cat /proc/sys/kernel/random/uuid to generate a UUID.
  6. Replace <UPSTREAM-UUID> in v2ray.json with the generated UUID.
  7. Replace <EXAMPLE.COM> in caddy/Caddyfile with your domain/subdomain.
  8. If ufw is installed and enabled, run ufw allow 80 and ufw allow 443 commands.
  9. Run docker compose up -d.
  10. Visit your domain/subdomain in your web browser. Wait until the homepage is loaded.
  11. In the CDN panel, enable the proxy option for the record created during the first step.
  12. Run ./vmess.py to generate client configuration.
  13. (Optional) Run ./../utils/bbr.sh to setup BBR and speed up the server network.

Notes

V2Ray as Relay for Outline

The "V2Ray as Relay for Outline" configuration is similar to the "V2Ray Upstream and Relay Servers" configuration, but it uses Outline on the upstream server instead of V2Ray. While the overall quality is comparable, Outline has a user-friendly management tool for easier user and traffic management.

You can find this configuration in the Outline Bridge Server repository.

Client Applications

Shadowsocks Protocol

This is the list of recommended applications for Shadowsocks protocol:

VMess Protocol

This is the list of recommended applications for VMess protocol:

HTTP and SOCKS Protocols

Moved to HTTP & SOCKS Protocols.

Links