From d4155625e45bf91577d8281d8d619c43ff7296f0 Mon Sep 17 00:00:00 2001 From: idk Date: Mon, 14 Nov 2022 18:55:21 +0000 Subject: [PATCH] Allow passing the IP address where the router console is reachable when running a Docker container --- Docker.md | 11 +++++++++++ docker/rootfs/startapp.sh | 10 +++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Docker.md b/Docker.md index fbe5d7e20..b1bff2f22 100644 --- a/Docker.md +++ b/Docker.md @@ -28,6 +28,17 @@ docker build -t i2p . ### Running a container +#### Environment Variables + +It is possible to set the IP address where the I2P router is accessible by setting +the `IP_ADDR` environment variable in your `docker run` command or your `docker-compose` +file. For example, if you want to make your I2P router listen on all addresses, then +you should pass `-e IP_ADDR=0.0.0.0` to your `docker run` command. + +It is also possible to configure the memory available to the I2P router using +environment variables. To do this, use the: `JVM_XMX` environment variable by passing, +for example, `-e JVM_XMX=256m`. + #### Volumes The container requires a volume for the configuration data to be mounted. Optionally, you can mount a separate volume for torrent ("i2psnark") downloads. See the example below. diff --git a/docker/rootfs/startapp.sh b/docker/rootfs/startapp.sh index 9fe95f81f..8cafdeb26 100644 --- a/docker/rootfs/startapp.sh +++ b/docker/rootfs/startapp.sh @@ -24,12 +24,13 @@ done if [ -f /.dockerenv ]; then echo "[startapp] Running in container" - export IP_ADDR=$(hostname -i) - if echo "$IP_ADDR" | grep "172.17"; then + if [ -z "$IP_ADDR" ]; then + export IP_ADDR=$(hostname -i) echo "[startapp] Running in docker network" - sed -i "s/127.0.0.1/${IP_ADDR}/g" ./clients.config ./i2ptunnel.config fi - + echo "[startapp] setting reachable IP to container IP $IP_ADDR" + find . -name '*.config' -exec sed -i "s/127.0.0.1/$IP_ADDR/g" {} \; + find . -name '*.config' -exec sed -i "s/localhost/$IP_ADDR/g" {} \; fi # Options required for reflective access in dynamic JVM languages like Groovy and Jython @@ -38,4 +39,3 @@ JAVA17OPTS="--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/su JAVAOPTS="-Djava.net.preferIPv4Stack=false -Djava.library.path=${I2P}:${I2P}/lib -Di2p.dir.base=${I2P} -Di2p.dir.config=${HOME}/.i2p -DloggerFilenameOverride=logs/log-router-@.txt -Xmx$JVM_XMX" java -cp "${CLASSPATH}" ${JAVA_OPTS} net.i2p.router.RouterLaunch -