So I've been struggling with how to deploy a dockerized application. The app consists of a react frontend, and an express API.
My docker-compose.yml for the development environment looks like the following:
version: '3'
services:
# Express Container
backend:
build: ./backend
expose:
- ${BACKEND_PORT}
env_file:
- ./.env
environment:
- PORT=${BACKEND_PORT}
ports:
- ${BACKEND_PORT}:${BACKEND_PORT}
volumes:
- ./backend:/backend
command: npm run devstart
links:
- mongo
# React Container
frontend:
build: './frontend'
expose:
- ${REACT_APP_PORT}
env_file:
- ./.env
environment:
- REACT_APP_BACKEND_PORT=${BACKEND_PORT}
ports:
- ${REACT_APP_PORT}:${REACT_APP_PORT}
volumes:
- ./frontend/src:/frontend/src
- ./frontend/public:/frontend/public
links:
- backend
command: npm start
mongo:
image: mongo
ports:
- "27017:27017"
But I've been struggling on how to structure it for production.
I've seen that there is basically 3 options:
- Deploy the frontend and backend separately to different servers. In this case, the react frontend would be on some web hosting service, and the express backend would be hosted on kubernetes
- Have the express application serve out the react application
- Have the applications separate but use NGINX to proxy API requests to the express app
I was thinking I would go with option 3, because it would keep development and production environments quite similar. (Please tell me if this is bad structure, this application is expected to receive a lot of traffic.)
Should I maybe forget docker-compose and create a multistage dockerfile that uses multistage builds to copy over frontend and backend code? That way I can deploy a single Docker container?
My folder structure looks like the following:
app/
.env
docker-compose.yml
docker-compose.prod.yml
.gitignore
frontend/
Dockerfile
... react stuff
backend
Dockerfile
.. express stuff
Am I going about this all wrong? How have you deployed your applications with docker-compose to production (preferably on kubernetes).
I can find tons of stuff about how to get this stuff running in development, but I'm lost when it comes to direction for deploying this type of stack.