You can build applications that consist of multiple interconnected services, such as frontend and backend components.
Single repository approach is recommended:
Example structure:
/my-application
/frontend
Dockerfile
/src
...
/backend
Dockerfile
/src
...
Services can communicate with each other in two primary ways:
For a typical web application with frontend and backend components:
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://${BACKEND_URL}/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
# ... other Dockerfile instructions ...
# Copy the Nginx template
COPY default.conf.template /etc/nginx/templates/
# Use envsubst to process the template
CMD ["/bin/sh", "-c", "envsubst '${BACKEND_URL}' < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"]
When creating the frontend service:
For applications with interdependent services: