Refactor Docker example

Problem: The Docker example was using Alpine with the Tini dependency
and some neat custom stuff, but it wasn't super clear to understand
everything that was going on. It was also slow because lots of stuff was
compiling from source.

Solution: Replace neat custom stuff with boring defaults for clarity and
much faster builds.
This commit is contained in:
Christian Bundy 2020-05-10 13:49:24 -07:00
parent 58765f8b0e
commit a5d5e446c7
3 changed files with 28 additions and 16 deletions

View File

@ -1 +1,2 @@
node_modules node_modules
.git

View File

@ -1,16 +1,25 @@
FROM node:12-alpine FROM node:lts
RUN apk add --update --no-cache libtool autoconf automake alpine-sdk python3
RUN mkdir /app # Ensure that the ~/.ssb directory is persistent and owned by the 'node' user.
WORKDIR /app RUN mkdir /home/node/.ssb && chown node:node /home/node/.ssb
ADD package.json . VOLUME /home/node/.ssb
ADD package-lock.json .
# Don't run as root.
USER node
# Create app directory and use it.
RUN mkdir /home/node/app
WORKDIR /home/node/app
# Add dependency metadata and install dependencies.
ADD package.json package-lock.json ./
RUN npm ci RUN npm ci
ADD . ./
EXPOSE 3000 # Add the rest of the source code.
EXPOSE 8008 ADD ./ ./
VOLUME /root/.ssb
ADD https://github.com/just-containers/s6-overlay/releases/download/v1.21.8.0/s6-overlay-amd64.tar.gz /tmp/ # Expose ports for Oasis and SSB replication.
RUN tar xzf /tmp/s6-overlay-amd64.tar.gz -C / EXPOSE 3000 8008
RUN mkdir /etc/services.d/oasis/
RUN printf "#!/usr/bin/execlineb -P\n/usr/local/bin/node /app/src/index.js --host 0.0.0.0 --open false" >> /etc/services.d/oasis/run # Listen on the container's public interfaces but allow 'localhost' connections.
ENTRYPOINT ["/init"] CMD ["node", ".", "--host", "0.0.0.0", "--allow-host", "localhost"]

View File

@ -14,5 +14,7 @@ docker volume create ssb
## Run ## Run
``` ```
docker run --mount source=ssb,target=/root/.ssb --publish 3000:3000 --rm oasis docker run --mount source=ssb,target=/home/node/.ssb --publish 127.0.0.0:3000:3000 --rm oasis
``` ```
You should now be able to open http://localhost:3000 in your browser.