Improve Dockerfile
* 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
Knut Ahlers committed
Apr 23, 2015 at 22:40 UTC
3534b039f7ccc3176aa5b922897a3c563d1171c4
2 files changed
+30
-5
Dockerfile
+11
-2
@@ -1,14 +1,23 @@
1
FROM golang:1.4
2
MAINTAINER Brian Tiger Chow <btc@perfmode.com>
3
4
+ENV IPFS_PATH /data/ipfs
5
+
6
+RUN useradd -m -d /data -u 1000 ipfs && \
7
+ mkdir -p /data/ipfs && chown ipfs:ipfs /data/ipfs
8
+
9
+EXPOSE 4001 5001 8080
10
+# 4001 = Swarm, 5001 = API, 8080 = HTTP transport
11
+
12
+VOLUME /data/ipfs
13
+
14
ADD . /go/src/github.com/ipfs/go-ipfs
15
RUN cd /go/src/github.com/ipfs/go-ipfs/cmd/ipfs && go install
16
17
RUN cp /go/src/github.com/ipfs/go-ipfs/bin/container_daemon /usr/local/bin/start_ipfs && \
18
chmod 755 /usr/local/bin/start_ipfs
19
10
-EXPOSE 4001 5001 8080
11
-# 4001 = Swarm, 5001 = API, 8080 = HTTP transport
20
+USER ipfs
21
22
ENTRYPOINT ["/usr/local/bin/start_ipfs"]
23
bin/container_daemon
+19
-3
@@ -1,5 +1,21 @@
1
#!/bin/bash
2
-ipfs init
3
-ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
4
-ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
2
+
3
+# Test whether the mounted directory is writable for us
4
+if ( touch /data/ipfs/write_test 2>/dev/null ); then
5
+ rm /data/ipfs/write_test
6
+else
7
+ echo "ERR: /data/ipfs is not writable for user 'ipfs' (UID 1000)"
8
+ exit 1
9
+fi
10
+
11
+echo "Running $(ipfs version)..."
12
+
13
+if [ -e /data/ipfs/config ]; then
14
+ echo "Found ipfs repository. Not initializing."
15
+else
16
+ ipfs init
17
+ ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
18
+ ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
19
+fi
20
+
21
ipfs daemon