add Dockerfile based on @promasu 's work

This commit is contained in:
Mathilde Grünig 2023-05-16 15:02:52 +02:00
parent c94666efb7
commit 1f47ecbc59
1 changed files with 51 additions and 0 deletions

51
Dockerfile Normal file
View File

@ -0,0 +1,51 @@
# Multistage build to reduce image size and increase security
FROM node:lts-alpine AS build
# Install requirements to clone repository and install deps
RUN apk add --no-cache git
RUN npm install -g bower
# Create folder for cryptpad
RUN mkdir /cryptpad
WORKDIR /cryptpad
# Get cryptpad from repository submodule
COPY . /cryptpad
RUN sed -i "s@//httpAddress: '::'@httpAddress: '0.0.0.0'@" /cryptpad/config/config.example.js
RUN sed -i "s@installMethod: 'unspecified'@installMethod: 'docker-alpine'@" /cryptpad/config/config.example.js
# Install dependencies
RUN npm install --production \
&& npm install -g bower \
&& bower install --allow-root
# Create actual cryptpad image
FROM node:lts-alpine
# Create user and group for cryptpad so it does not run as root
RUN addgroup -g 4001 -S cryptpad \
&& adduser -u 4001 -S -D -g 4001 -H -h /cryptpad cryptpad
# Copy cryptpad with installed modules
COPY --from=build --chown=cryptpad /cryptpad /cryptpad
USER cryptpad
# Set workdir to cryptpad
WORKDIR /cryptpad
# Create directories
RUN mkdir blob block customize data datastore
# Volumes for data persistence
VOLUME /cryptpad/blob
VOLUME /cryptpad/block
VOLUME /cryptpad/customize
VOLUME /cryptpad/data
VOLUME /cryptpad/datastore
# Ports
EXPOSE 3000 3001
# Run cryptpad on startup
CMD ["npm", "start"]