Skip to content

Commit

Permalink
Update README with an example
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Caian Benedicto <[email protected]>
  • Loading branch information
Caian authored and lidel committed Sep 3, 2021
1 parent 26bb019 commit b88cebf
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,44 @@ Basic proof of 'ipfs working' locally:
# QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o
ipfs cat <that hash>

To perform a custom initialization and configuration step, one can create or mount a `/container-init.d` directory containing `.sh` scripts. These scripts are executed if they have `+x` permission, otherwise they are just sourced. The scripts may also depend on environment variables set by the `docker run` command or in `docker-compose.yml`. The custom initialization step is **only** performed during IPFS initialization and is executed **after** the swarm key is copied to the IPFS data directory.
To perform a custom initialization and configuration step, one can mount `.sh` scripts to a `/container-init.d` directory, or mount the entire directory. These scripts are executed if they have `+x` permission, otherwise they are just sourced. Executed scripts can exit with error and abort the initialization process. The scripts may also depend on environment variables set by the `docker run` command or in `docker-compose.yml`. The custom initialization step is **only** performed during IPFS initialization, **after** `ipfs init`, **after** after the swarm key is copied to the IPFS data directory, and **before** the daemon is started. This also enables custom containers to layer extra initialization steps to the base image by adding more scripts to `/container-init.d`.

This example initializes a peer in a private network, without any communication with the default bootstrap nodes because it is performed before the daemon starts:

# This is the initialization script
TEST_NAME=00-test.sh
TEST_SCRIPT=`pwd`/$TEST_NAME

# The script will add this node when creating the container
MY_PEER_IP=127.0.0.1
MY_PEER_HASH=QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ

# For instructional purposes, create the initialization script here,
# but this may be part of a suite of scripts maintained by the IT team,
# or created inside a custom Dockerfile.
cat >$TEST_SCRIPT <<EOF
echo Removing boostraps...
ipfs bootstrap rm all || exit 1
echo Adding custom boostrap from environment...
MULTIADDR=/ip4/\$MY_PEER_IP/tcp/4001/ipfs/\$MY_PEER_HASH
ipfs bootstrap add \$MULTIADDR || exit 1
exit 0
EOF

# Set the script as executable
chmod +x $TEST_SCRIPT

# Initialize the container with the custom scripted mounted.
# It is also possible to mount the entire /container-init.d
# rather than a single
docker run -d --name ipfs_host \
-e MY_PEER_IP=$MY_PEER_IP \
-e MY_PEER_HASH=$MY_PEER_HASH \
-v $TEST_SCRIPT:/container-init.d/$TEST_NAME \
-p 4001:4001 \
-p 127.0.0.1:8080:8080 \
-p 127.0.0.1:5001:5001 \
ipfs/go-ipfs:latest

### Troubleshooting

Expand Down

0 comments on commit b88cebf

Please sign in to comment.