Browse Source

entrypoint: support changing gateway address & port via environment variable IPFS_GATEWAY_ADDR (default: 127.0.0.1:8080)

Fabian Peter Hammerle 1 year ago
parent
commit
f7d1468432
5 changed files with 19 additions and 1 deletions
  1. 4 0
      CHANGELOG.md
  2. 1 0
      Dockerfile
  3. 6 0
      README.md
  4. 4 1
      docker-compose.yml
  5. 4 0
      entrypoint.sh

+ 4 - 0
CHANGELOG.md

@@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
 ## [Unreleased]
+### Added
+- entrypoint: support changing gateway address & port via environment variable `IPFS_GATEWAY_ADDR`
+  (e.g. `IPFS_GATEWAY_ADDR=/ip4/0.0.0.0/tcp/8080` to listen on all ipv4 interfaces)
+
 ### Fixed
 - docker-compose: remove unsuppported option `volumes[].tmpfs.mode`
 

+ 1 - 0
Dockerfile

@@ -39,6 +39,7 @@ ENV IPFS_CONFIG_PATH="${IPFS_PATH}/config" \
     IPFS_INIT_PROFILE=server \
     IPFS_API_ADDR=/ip4/0.0.0.0/tcp/5001 \
     IPFS_SWARM_ADDRS=/ip4/0.0.0.0/tcp/4001 \
+    IPFS_GATEWAY_ADDR=default \
     IPFS_BOOTSTRAP_ADD=
 COPY entrypoint.sh /
 RUN chmod a=rx /entrypoint.sh

+ 6 - 0
README.md

@@ -29,6 +29,12 @@ docker run --name ipfs \
     fphammerle/ipfs:latest
 ```
 
+## Publish HTTP Gateway
+
+```sh
+docker run -e IPFS_GATEWAY_ADDR=/ip4/0.0.0.0/tcp/8080 -p 8080:8080 …
+```
+
 ## Change [Swarm Listener Ports](https://github.com/ipfs/go-ipfs/blob/v0.8.0/docs/config.md#addressesswarm)
 
 ```sh

+ 4 - 1
docker-compose.yml

@@ -5,9 +5,11 @@ volumes:
 
 services:
   ipfs:
+    container_name: ipfs
     build: .
     image: docker.io/fphammerle/ipfs
-    container_name: ipfs
+    #environment:
+    #  IPFS_GATEWAY_ADDR: /ip4/0.0.0.0/tcp/8080
     read_only: true
     volumes:
     - type: volume
@@ -22,6 +24,7 @@ services:
     ports:
     - '4001:4001'
     - '127.0.0.1:5001:5001'
+    #- '127.0.0.1:8080:8080' # requires IPFS_GATEWAY_ADDR=/ip4/0.0.0.0/tcp/8080
     cap_drop: [ALL]
     security_opt: [no-new-privileges]
     restart: unless-stopped

+ 4 - 0
entrypoint.sh

@@ -26,6 +26,10 @@ if [ "$IPFS_SWARM_ADDRS" != "default" ]; then
     ipfs_config_jq_edit '.Addresses.Swarm |= $ARGS.positional' --args $IPFS_SWARM_ADDRS
 fi
 
+if [ "$IPFS_GATEWAY_ADDR" != "default" ]; then
+    ipfs_config_jq_edit '.Addresses.Gateway = $ARGS.positional[0]' --args "$IPFS_GATEWAY_ADDR"
+fi
+
 # compare https://github.com/ipfs/go-ipfs/blob/v0.11.0/docs/config.md#peering
 if [ ! -z "$IPFS_BOOTSTRAP_ADD" ]; then
     # + ipfs bootstrap add -- /dnsaddr/...