My first V2Ray client already used port 10809. I wanted to keep it running and start a second client, v2ray2, with its own configuration. I changed the port in the second file, but the new container exited almost immediately. Before changing any more ports, I needed to answer two questions. Which file was the program actually reading? How far did it get with that file?
Which copy of the configuration does the second container see?
The short process listing showed v2ray -config=/et.... Even the full command would tell me only where V2Ray looks inside the container. Podman can make a directory on the host visible at a different path inside the container. This is a bind mount. To find the file on the host, inspect the running command and the mount together. Podman keeps this information for stopped containers too.
podman inspect v2ray2
| Field | Value in my container | What it tells me |
|---|---|---|
Path and Args | v2ray -config=/etc/v2ray/config.json | Which file V2Ray opens inside the container |
Mounts → Source, Destination | /etc/v2ray-backup → /etc/v2ray | Which host directory supplies that file |
HostConfig → NetworkMode | host | Where V2Ray will listen if it starts |
Together the first two rows identify /etc/v2ray-backup/config.json on the host. The third explains why I changed the listening port. I ran Podman as an ordinary user (rootless mode) and chose --network=host, so the second client would listen directly on the host. It needed a free listening address and port combination. Rootless Podman also supports publishing a host port to a container on an isolated network with -p. I covered that arrangement in An Introduction to Podman.1
I hit a shell error on the way to creating this container. My command had a line ending in --network=host \ # Shares host network namespace. In Bash, a backslash continues a command only when the very next character is the newline. Here it escaped a space. Podman reported invalid reference format, and Bash tried to run the next line as a new command, producing -v: command not found. Moving the comment above the command gives this corrected form for creating the second container:2
# Use the second client's configuration on the host network.
podman run -d --name v2ray2 \
--network=host \
-v /etc/v2ray-backup:/etc/v2ray \
docker.io/v2ray/official
Did V2Ray reach the point where it opens a port?
Once the container existed, podman inspect showed State.ExitCode was 23. Its environment also included HTTP_PROXY=http://127.0.0.1:10809/. That variable tells programs that honor it where to send an outgoing request. V2Ray’s inbound configuration tells it where to listen. Seeing the old port in the environment left the cause of the exit open.
The decisive command was podman logs v2ray2. The program identified itself as V2Ray 4.22.1 and reported this error near the end of the message:
failed to read config file at line 58 char 24 > invalid character 'a' after object key:value pair
JSON stores named values in pairs such as "port": 10001. After a complete value in an object, the parser expects a comma before the next pair or a closing brace. It encountered an a instead. Line 58, character 24 is where the parser detected the problem. The mistake could begin earlier, so it helps to see the preceding lines too.
nl -ba /etc/v2ray-backup/config.json | sed -n '54,62p'
The version matters here. In 4.22.1, V2Ray loads the configuration and constructs the service before it calls the function that starts listening. An error during that preparation can produce exit code 23. The log narrowed this particular failure to reading the JSON. Stopping the working client to free port 10809 would leave the same parse error.3
How can I check an edit while the first client keeps running?
Version 4.22.1 has a -test option that reads the configuration and exits before starting the service. After editing the host file, run the test with the same local image as the failed container. The local image ID in my listing was 77469193c529. Use the ID from your own inspection so the test uses the same binary even if the latest tag has moved.3
podman run --rm \
-v /etc/v2ray-backup:/etc/v2ray:ro \
77469193c529 v2ray -test -config=/etc/v2ray/config.json
If the test prints Configuration OK., start the existing second container with podman start v2ray2. Check podman ps to see whether it stays up and podman logs v2ray2 for any new startup error. A successful configuration test still leaves the actual port bind to be tested at startup.
My last log identifies the malformed JSON. I don’t have the corrected line or a later successful startup. Getting both clients to stay up was the prerequisite for the original question, Can GNOME’s proxy settings load-balance two local V2Ray clients?
Footnotes
-
Podman contributors. (n.d.). podman-run (v5.3.2). Podman documentation, network mode and volume mounts. ↩
-
IEEE & The Open Group. (2024). Shell command language. The Open Group Base Specifications, Issue 8, §2.2.1, “Escape Character (Backslash)”. ↩
-
V2Ray contributors. (n.d.). main.go (v4.22.1). GitHub,
startV2Rayandmain. ↩ ↩2