Deploy V2Ray with Docker Compose
Update from the original repo:
- Add additional notes for trouble shooting
- Update guidelines such as the latest usage of docker compose
Steps
1. Setup VPS
Using Azure as an example
- Create a Virtual Machine
- Any kind of Size (schema) will work, but you can use exactly the same as mine
- Size: Standard B2s (2 vcpus, 4 GiB memory)
- Operating system: Linux (ubuntu 20.04)
- Location: Japan East
- Disk: Standard SSD
- Make sure you disable the auto-shutdown scheduling
- Any kind of Size (schema) will work, but you can use exactly the same as mine
- Once the VM creation complete
- Open necessary ports, in this case you need to open 80, 443
- Create a DNS name: such as
your-dns-name
- You can use a dynamic IP address
- You will be able to connect to your machine by using
your-dns-name.japaneast.cloudapp.azure.com
depending on the machine's location
2. Setup Environment
ssh
into your machine
- Install
docker
- Download auto setup script and run:
curl -fsSL https://get.docker.com -o get-docker.sh
thensh get-docker.sh
- Add user to docker user group (so you don't need
sudo
to usedocker
):gpasswd -a $USER docker
- Make docker auto start on boot:
sudo systemctl start docker
thensudo systemctl enable docker
- Download auto setup script and run:
- Install
docker compose
(Install Docker Compose | Docker Documentation)DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.4.1/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
3. Clone Code and Config
- Download some CLI tools
sudo apt update
sudo apt install git vim tmux
git clone https://github.com/daviddwlee84/DockerCompose-V2Ray.git
andcd DockerCompose-V2Ray
- Modify settings
init-letsencrypt.sh
- Modify
domains
andemail
to be your own - If you are using Azure, the
domains
isyour-dns-name.japaneast.cloudapp.azure.com
- Note that
domains
SHOULD BE AN ARRAY, that is you should keep the parenthesis there.
- Modify
docker-compose.yml
- No need to modify
data/v2ray/config.json
- Change id to use your own
"id": "bae399d4-13a4-46a3-b144-4af2c0004c2e"
(or you can leave it as what it is) - You can generate new UUID using this online tool: Online UUID Generator Tool
- Change id to use your own
data/nginx/conf.d/v2ray.conf
(but currently it will be override byinit-letsencrypt.sh
?! whatever)- Modify all
your_domain
- You can use vim
:%s/your_domain/your-dns-name.japaneast.cloudapp.azure.com/g
- Modify all
- Setup Nginx and HTTPS encryption stuff
chmod +x ./init-letsencrypt.sh
./init-letsencrypt.sh
- Start server
tmux
docker compose up
You should be able to close your terminal now
4. Config Your Client
- Address:
your-dns-name.japaneast.cloudapp.azure.com
- Port:
443
- UUID:
bae399d4-13a4-46a3-b144-4af2c0004c2e
- Alert ID: 64
- Method: auto
- TLS
- enable
- allow insecure
- Transport:
websocket
- Path:
/v2ray
- Path:
Trouble Shooting
You can see logs/
folder
Use sudo tail -f ./path/to/log.log
to see the error message then debug
- If you forgot to open
80,443
ports, you will fail at certbot step. Removedata/certbot
folder and try again. - If your Nginx server successfully running, you can connect to
https://your-dns-name.japaneast.cloudapp.azure.com
using a browser and see "Congratulation!" which basically is this HTML (data/nginx/html/v2ray/index.html
) - You can connect to
https://your-dns-name.japaneast.cloudapp.azure.com/v2ray
- If you get a 502 error, that means your V2Ray server is not running correctly.
- If you get the text "bad request", that means it successfully running.