Dockerfile 2.84 KB
Newer Older
Steven Allen's avatar
Steven Allen committed
1
FROM golang:1.11-stretch
Lars Gierth's avatar
Lars Gierth committed
2 3
MAINTAINER Lars Gierth <lgierth@ipfs.io>

4
# There is a copy of this Dockerfile called Dockerfile.fast,
Lars Gierth's avatar
Lars Gierth committed
5 6 7
# which is optimized for build time, instead of image size.
#
# Please keep these two Dockerfiles in sync.
8

9 10 11 12 13 14
ENV GX_IPFS ""
ENV SRC_DIR /go/src/github.com/ipfs/go-ipfs

COPY . $SRC_DIR

# Build the thing.
15 16
# Also: fix getting HEAD commit hash via git rev-parse.
# Also: allow using a custom IPFS API endpoint.
17 18 19 20 21
RUN cd $SRC_DIR \
  && mkdir .git/objects \
  && ([ -z "$GX_IPFS" ] || echo $GX_IPFS > /root/.ipfs/api) \
  && make build

22 23
# Get su-exec, a very minimal tool for dropping privileges,
# and tini, a very minimal init daemon for containers
24 25 26 27 28 29 30 31 32 33 34 35 36
ENV SUEXEC_VERSION v0.2
ENV TINI_VERSION v0.16.1
RUN set -x \
  && cd /tmp \
  && git clone https://github.com/ncopa/su-exec.git \
  && cd su-exec \
  && git checkout -q $SUEXEC_VERSION \
  && make \
  && cd /tmp \
  && wget -q -O tini https://github.com/krallin/tini/releases/download/$TINI_VERSION/tini \
  && chmod +x tini

# Get the TLS CA certificates, they're not provided by busybox.
37
RUN apt-get update && apt-get install -y ca-certificates
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

# Now comes the actual target image, which aims to be as small as possible.
FROM busybox:1-glibc
MAINTAINER Lars Gierth <lgierth@ipfs.io>

# Get the ipfs binary, entrypoint script, and TLS CAs from the build container.
ENV SRC_DIR /go/src/github.com/ipfs/go-ipfs
COPY --from=0 $SRC_DIR/cmd/ipfs/ipfs /usr/local/bin/ipfs
COPY --from=0 $SRC_DIR/bin/container_daemon /usr/local/bin/start_ipfs
COPY --from=0 /tmp/su-exec/su-exec /sbin/su-exec
COPY --from=0 /tmp/tini /sbin/tini
COPY --from=0 /etc/ssl/certs /etc/ssl/certs

# This shared lib (part of glibc) doesn't seem to be included with busybox.
COPY --from=0 /lib/x86_64-linux-gnu/libdl-2.24.so /lib/libdl.so.2
Knut Ahlers's avatar
Knut Ahlers committed
53

54
# Swarm TCP; should be exposed to the public
Lars Gierth's avatar
Lars Gierth committed
55
EXPOSE 4001
56
# Daemon API; must not be exposed publicly but to client services under you control
Lars Gierth's avatar
Lars Gierth committed
57
EXPOSE 5001
58
# Web Gateway; can be exposed publicly with a proxy, e.g. as https://ipfs.example.org
Lars Gierth's avatar
Lars Gierth committed
59
EXPOSE 8080
60
# Swarm Websockets; must be exposed publicly when the node is listening using the websocket transport (/ipX/.../tcp/8081/ws).
61
EXPOSE 8081
Knut Ahlers's avatar
Knut Ahlers committed
62

63
# Create the fs-repo directory and switch to a non-privileged user.
Lars Gierth's avatar
Lars Gierth committed
64
ENV IPFS_PATH /data/ipfs
65
RUN mkdir -p $IPFS_PATH \
66 67
  && adduser -D -h $IPFS_PATH -u 1000 -G users ipfs \
  && chown ipfs:users $IPFS_PATH
68

kpcyrd's avatar
kpcyrd committed
69
# Expose the fs-repo as a volume.
70 71
# start_ipfs initializes an fs-repo if none is mounted.
# Important this happens after the USER directive so permission are correct.
kpcyrd's avatar
kpcyrd committed
72 73
VOLUME $IPFS_PATH

74 75
# The default logging level
ENV IPFS_LOGGING ""
76

Lars Gierth's avatar
Lars Gierth committed
77 78 79
# This just makes sure that:
# 1. There's an fs-repo, and initializes one if there isn't.
# 2. The API and Gateway are accessible from outside the container.
kpcyrd's avatar
kpcyrd committed
80
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/start_ipfs"]
81 82

# Execute the daemon subcommand by default
kpcyrd's avatar
kpcyrd committed
83
CMD ["daemon", "--migrate=true"]