fydq/xray-core

By fydq

Updated about 2 years ago

xray-core built exactly from official source code, w/ documentation on how you can build it yourself

Image
Networking
0

10K+

fydq/xray-core repository overview

This is a proof of concept docker build for xray-core, to demonstrate how you can easily build it from source.

The chain of trust includes only:

  • the official xray-core source code
  • github
  • official docker team
  • the OS where you are building this docker container
  • your server, and
  • you

The problem

While there is the official docker build and some unofficial builds, blindly trusting any binaries can be potentially dangerous and life-threatening in suppressing regimes such as China, a risk perhaps you may not want to take.

You should NOT fully trust any unofficial builds, not even when the builder opensources their workflow, because how can anyone prove the provided builds are actually generated from the workflow, until one builds for themselves to reproduce it.

For the sake of the argument, you may not fully trust the official builds, either, unless the official builds have been consistently shown to be reproducible.

The solution

It is for these reasons that this documentation will be focusing on how you can build the xray-core docker on your own.

Note: For the same reasons, you should NOT trust my docker builds, either; instead, please read on and see how you can build one for yourself.

Preparation

You need some basic understanding of git, docker and commandline, and if you are a frequent user of docker, it's probably not an issue.

This documentation is based on Linux, but the general ideas apply to macOS and Windows, too.

How to build it yourself

  1. Clone the official xray-core git repo:

    git clone https://github.com/XTLS/Xray-core.git

  2. Open your terminal and enter the Xray-core directory:

    cd Xray-core

  3. Tell git which version you want to use, in this example, it'll be v1.8.13:

    git checkout tags/v1.8.13

  4. Build the docker with just 1 simple command, based on the Dockerfile inside ./github/docker:

    docker build -t xray-core . -f .github/docker/Dockerfile

    tip: you may need sudo permission; alternatively, you can manager docker as a non-sudo user.

  5. That's it, the docker container is ready to use, and you can see the image by running:

    docker images | grep xray

Updating

  1. Let's assume the latest version is now 5.3.10, replace the Steps 1, 2 and 3 above with this:

    cd Xray-core && git pull && git checkout tags/v5.3.10

  2. Continue with Steps 4 and 5 above.

Publish the docker (optional)

This may come handy when you want to build the docker once and deploy it elsewhere.

  1. Only for the 1st time: visit docker hub and create an account.

    Tip: user an email address that has nothing to do with your real-world life, such that even this account is compromised, it cannot be traced back to you. Use VPN / tor as well.

  2. In your terminal, run:

    docker login

    enter your username and password

  3. Re-tag your repo using this format: my_username/repo:

    docker tag xray-core my_username/xray-core

  4. Checking it for errors:

    docker images | grep xray

  5. If everything looks good, push it to dockerhub:

    docker push my_username/xray-core

  6. The docker container can now be used by any server when running:

    docker run -d my_username/xray-core ...

    or if you're using docker compose, your docker-compose.yaml file can look something like this:

version: '3.1'
services:
  xray:
    image: my_username/xray-core
    container_name: xray-core
    restart: unless-stopped
    ports:
      - 443:443
    #environment:
      # https://xtls.github.io/en/config/features/env.html
      # XRAY_LOCATION_CONFDIR: /etc/xray/ # Enable multi-config mode
    volumes:
      - ./config_server.json:/etc/xray/config.json
      - ./log/:/var/log/xray/

Note:

  1. For examples of config_server.json, please refer to chika0801's collection of Xray-examples.
  2. Only for the 1st time, please create a log directory first, or the docker may not run

Tag summary

Content type

Image

Digest

sha256:0e7e21839

Size

18.4 MB

Last updated

about 2 years ago

docker pull fydq/xray-core