Skip to content

Commit

Permalink
Improve Dockerfile
Browse files Browse the repository at this point in the history
* Added VOLUME to enable users to keep a state of the repo outside the container
* Added ipfs user to let ipfs run as a normal user and not as root
* Set IPFS_PATH to push IPFS to use the exposed dir
* Improved start script to be more verbose about errors
  • Loading branch information
Luzifer committed Apr 23, 2015
1 parent 83ca015 commit 3534b03
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
13 changes: 11 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
FROM golang:1.4
MAINTAINER Brian Tiger Chow <btc@perfmode.com>

ENV IPFS_PATH /data/ipfs

RUN useradd -m -d /data -u 1000 ipfs && \
mkdir -p /data/ipfs && chown ipfs:ipfs /data/ipfs

EXPOSE 4001 5001 8080
# 4001 = Swarm, 5001 = API, 8080 = HTTP transport

VOLUME /data/ipfs

ADD . /go/src/github.com/ipfs/go-ipfs
RUN cd /go/src/github.com/ipfs/go-ipfs/cmd/ipfs && go install

RUN cp /go/src/github.com/ipfs/go-ipfs/bin/container_daemon /usr/local/bin/start_ipfs && \
chmod 755 /usr/local/bin/start_ipfs

EXPOSE 4001 5001 8080
# 4001 = Swarm, 5001 = API, 8080 = HTTP transport
USER ipfs

ENTRYPOINT ["/usr/local/bin/start_ipfs"]

Expand Down
22 changes: 19 additions & 3 deletions bin/container_daemon
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/bin/bash
ipfs init
ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080

# Test whether the mounted directory is writable for us
if ( touch /data/ipfs/write_test 2>/dev/null ); then
rm /data/ipfs/write_test
else
echo "ERR: /data/ipfs is not writable for user 'ipfs' (UID 1000)"
exit 1
fi

echo "Running $(ipfs version)..."

if [ -e /data/ipfs/config ]; then
echo "Found ipfs repository. Not initializing."
else
ipfs init
ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
fi

ipfs daemon

0 comments on commit 3534b03

Please sign in to comment.