changwenhan's picture
Update Dockerfile
84df427 verified
# Use an official Node.js LTS version that uses glibc
FROM node:18-bullseye-slim
# Install sysctl (procps package)
RUN apt-get update && apt-get install -y procps && rm -rf /var/lib/apt/lists/*
# Set the working directory in the container
WORKDIR /app
# Copy the package.json and package-lock.json (if available)
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy the rest of the application code
COPY . .
# Expose the port the app runs on
EXPOSE 7860
# Create an entrypoint script to set sysctl settings
RUN echo "#!/bin/sh" > /entrypoint.sh && \
echo "sysctl -w net.ipv4.ip_local_port_range='1024 65535'" >> /entrypoint.sh && \
echo "sysctl -w net.ipv4.tcp_mem='131072 262144 524288'" >> /entrypoint.sh && \
echo "sysctl -w net.ipv4.tcp_rmem='8760 256960 4088000'" >> /entrypoint.sh && \
echo "sysctl -w net.ipv4.tcp_wmem='8760 256960 4088000'" >> /entrypoint.sh && \
echo "sysctl -w net.core.rmem_max=16384" >> /entrypoint.sh && \
echo "sysctl -w net.core.wmem_max=16384" >> /entrypoint.sh && \
echo "sysctl -w net.core.somaxconn=2048" >> /entrypoint.sh && \
echo "sysctl -w net.ipv4.tcp_max_syn_backlog=2048" >> /entrypoint.sh && \
echo "sysctl -w net.core.netdev_max_backlog=2048" >> /entrypoint.sh && \
echo "sysctl -w net.ipv4.tcp_tw_reuse=1" >> /entrypoint.sh && \
echo "ulimit -n 2000500 || true" >> /entrypoint.sh && \
echo "exec \"\$@\"" >> /entrypoint.sh && \
chmod +x /entrypoint.sh
# Use the entrypoint script
ENTRYPOINT ["/entrypoint.sh"]
# Run the application
CMD ["npm", "start"]