TrustworthyAI / Dockerfile
Peiyan's picture
Update Dockerfile
2b02f32 verified
raw
history blame
1.61 kB
# Step #1: build the React front end
FROM node:14-bullseye-slim as build-step
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
RUN mkdir ./frontend
COPY ./frontend/package.json ./frontend/package-lock.json ./frontend/
WORKDIR /app/frontend
RUN npm install -g [email protected]
# It's OK to have multiple consecutive `RUN` instructions.
# hadolint ignore=DL3059
RUN npm install
WORKDIR /app
COPY ./frontend ./frontend
WORKDIR /app/frontend
RUN npm run build
# Step #2: set up the Python backend and Nginx
FROM python:3.10.13-slim-bullseye
RUN apt-get update && apt-get install -y nginx \
&& rm -rf /var/lib/apt/lists/*
RUN python3 -m pip install --upgrade pip \
&& pip install gunicorn==20.1.0
# Copy backend code and install dependencies
COPY ./backend ./backend
RUN pip install -r ./backend/requirements.txt
# Ensure necessary permissions and create directories
RUN mkdir -p /var/log/nginx && \
touch /var/log/nginx/error.log && \
touch /var/log/nginx/access.log && \
chmod -R 777 /var/log/nginx && \
chown -R root:root /var/log/nginx && \
chmod -R 777 /var/lib/nginx && \
chown -R root:root /var/lib/nginx && \
chmod -R 777 /usr/share/nginx/html && \
chown -R root:root /usr/share/nginx/html && \
mkdir -p /run && \
chmod -R 777 /run
# Step #3: Configure nginx and flask
COPY --from=build-step /app/frontend/build /var/www/html
COPY deployment/docker/nginx.conf /etc/nginx/sites-enabled/default
COPY deployment/docker/serve.sh .
RUN chmod +x ./serve.sh
# Expose port 8080
EXPOSE 8080
# Run as root user
USER root
ENTRYPOINT ["/bin/bash"]
CMD ["/serve.sh"]