How to prepare a production server
When developing your application using one of our templates, you'll encounter simple entrypoints designed to facilitate development on the Divio Cloud Platform:
npm run preview
php artisan serve
./script
These entry points, configured via the CMD
directive in your Dockerfile
, are optimized for development rather than production use.
It's crucial to consult your specific language/framework documentation for guidance on deploying your application in a production environment. Although the following guide focuses on a React application, similar principles can be adapted for other technologies.
Deploying with Nginx
For demonstration purposes, we'll utilize the Getting started with React template. The project's Dockerfile
is outlined below:
FROM node:lts
WORKDIR /app
COPY package*.json /app/
RUN npm install
COPY . /app
RUN npm run build
EXPOSE 80
CMD ["npm", "run", "preview", "--", "--host", "0.0.0.0", "--port", "80"]
While npm run preview -- --host 0.0.0.0 --port 80
is adequate for environments like Test, it's unsuitable for Live deployment due to potential performance and stability issues. To address this, we'll incorporate an Nginx server to efficiently serve the React application in production. Here’s how to set it up:
FROM node:lts as build
WORKDIR /app
COPY package*.json /app/
RUN npm install
COPY . /app
RUN npm run build
FROM nginx:stable-alpine
COPY --from=build /app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
This configuration provides a clean separation of build and serve environments, minimizing the final image size and reducing potential security vulnerabilities in your production container.