Dockerfile 2.97 KB
Newer Older
1
FROM golang:1.13.6-buster
Jakub Kaczmarzyk's avatar
Jakub Kaczmarzyk committed
2
LABEL maintainer="Steven Allen <steven@stebalien.com>"
Lars Gierth's avatar
Lars Gierth committed
3

4
ENV SRC_DIR /go-ipfs
5

6 7 8 9
# Download packages first so they can be cached.
COPY go.mod go.sum $SRC_DIR/
RUN cd $SRC_DIR \
  && go mod download
10 11 12 13

COPY . $SRC_DIR

# Build the thing.
14
# Also: fix getting HEAD commit hash via git rev-parse.
15 16 17 18
RUN cd $SRC_DIR \
  && mkdir .git/objects \
  && make build

19 20
# Get su-exec, a very minimal tool for dropping privileges,
# and tini, a very minimal init daemon for containers
21 22 23 24 25 26 27 28 29 30 31 32 33
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.
34
RUN apt-get update && apt-get install -y ca-certificates
35

36 37 38
# Install FUSE
RUN apt-get update && apt-get install -y fuse

39
# Now comes the actual target image, which aims to be as small as possible.
Steven Allen's avatar
Steven Allen committed
40
FROM busybox:1.31.0-glibc
Jakub Kaczmarzyk's avatar
Jakub Kaczmarzyk committed
41
LABEL maintainer="Steven Allen <stven@stebalien.com>"
42 43

# Get the ipfs binary, entrypoint script, and TLS CAs from the build container.
44
ENV SRC_DIR /go-ipfs
45 46 47 48
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
49
COPY --from=0 /bin/fusermount /usr/local/bin/fusermount
50 51
COPY --from=0 /etc/ssl/certs /etc/ssl/certs

52 53 54
# Add suid bit on fusermount so it will run properly
RUN chmod 4755 /usr/local/bin/fusermount

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

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

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

73 74 75 76
# Create mount points for `ipfs mount` command
RUN mkdir /ipfs /ipns \
  && chown ipfs:users /ipfs /ipns

kpcyrd's avatar
kpcyrd committed
77
# Expose the fs-repo as a volume.
78 79
# 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
80 81
VOLUME $IPFS_PATH

82 83
# The default logging level
ENV IPFS_LOGGING ""
84

Lars Gierth's avatar
Lars Gierth committed
85 86 87
# 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
88
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/start_ipfs"]
89 90

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