mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
using docker without root
This commit is contained in:
15
Dockerfile
15
Dockerfile
@@ -12,7 +12,7 @@ ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
|
|||||||
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
|
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
|
||||||
|
|
||||||
# Copy lockfiles first to leverage cache for dependencies
|
# Copy lockfiles first to leverage cache for dependencies
|
||||||
COPY package.json yarn.lock .
|
COPY --chown=node:node package.json yarn.lock ./
|
||||||
|
|
||||||
# Set Yarn timeout, install dependencies and PM2 globally
|
# Set Yarn timeout, install dependencies and PM2 globally
|
||||||
RUN yarn config set network-timeout 600000 \
|
RUN yarn config set network-timeout 600000 \
|
||||||
@@ -20,13 +20,13 @@ RUN yarn config set network-timeout 600000 \
|
|||||||
&& yarn global add pm2
|
&& yarn global add pm2
|
||||||
|
|
||||||
# Copy application source and build production assets
|
# Copy application source and build production assets
|
||||||
COPY . .
|
COPY --chown=node:node . .
|
||||||
RUN yarn build:frontend
|
RUN yarn build:frontend
|
||||||
|
|
||||||
# Prepare runtime directories and symlinks for data and config
|
# Prepare runtime directories and symlinks for data and config (as root)
|
||||||
RUN mkdir -p /db /conf \
|
RUN mkdir -p /db /conf \
|
||||||
&& chown 1000:1000 /db /conf \
|
&& chown node:node /fredy /db /conf \
|
||||||
&& chmod 777 /db /conf \
|
&& chmod 770 /db /conf \
|
||||||
&& ln -s /db /fredy/db \
|
&& ln -s /db /fredy/db \
|
||||||
&& ln -s /conf /fredy/conf
|
&& ln -s /conf /fredy/conf
|
||||||
|
|
||||||
@@ -34,5 +34,8 @@ EXPOSE 9998
|
|||||||
VOLUME /db
|
VOLUME /db
|
||||||
VOLUME /conf
|
VOLUME /conf
|
||||||
|
|
||||||
|
# Change to non-root user
|
||||||
|
USER node
|
||||||
|
|
||||||
# Start application using PM2 runtime
|
# Start application using PM2 runtime
|
||||||
CMD ["pm2-runtime", "index.js"]
|
CMD ["pm2-runtime", "index.js"]
|
||||||
6
docker-test.sh
Normal file → Executable file
6
docker-test.sh
Normal file → Executable file
@@ -7,12 +7,12 @@ if [ "$(docker ps -aq -f name=fredy)" ]; then
|
|||||||
docker rm fredy || true
|
docker rm fredy || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Build image from local Dockerfile
|
# Build image from local Dockerfile, forcing a fresh build without cache
|
||||||
docker build -t fredy:local .
|
docker build --no-cache -t fredy:local .
|
||||||
|
|
||||||
# Run container with volumes and port mapping
|
# Run container with volumes and port mapping
|
||||||
docker run -d --name fredy \
|
docker run -d --name fredy \
|
||||||
-v fredy_conf:/conf \
|
-v fredy_conf:/conf \
|
||||||
-v fredy_db:/db \
|
-v fredy_db:/db \
|
||||||
-p 9998:9998 \
|
-p 9998:9998 \
|
||||||
fredy:local
|
fredy:local
|
||||||
Reference in New Issue
Block a user