Welcome! In this assignment, you are tasked with fixing a broken staging environment for our Real-Time Chat web application.
A junior developer recently attempted to containerize this application using Docker and NGINX, but the deployment is currently failing on multiple fronts. Your job is to debug their configuration files and get the application fully operational via Docker Compose.
The application is built using two primary containers:
- Backend (
backend): A Python-based FastAPI server operating on Port 8000. It handles persistent, real-time WebSocket connections on the/wsendpoint. - Frontend Proxy (
nginx): An NGINX container mapped to Port 80. It is responsible for serving the static files from thefrontend/directory, while simultaneously intercepting and reverse-proxying all WebSocket upgrade requests down to the backend container.
realtime-chat-app/
├── app/
│ ├── main.py # FastAPI application server
│ └── requirements.txt # Python dependencies
├── frontend/
│ └── index.html # Simple, styled single-page HTML client
├── Dockerfile # Instructions to build the Python backend image
├── docker-compose.yml # Composes both NGINX and Python Backend services
└── nginx.conf # Configuration for NGINX routing and WS proxy
If you run docker-compose up -d --build right now, the containers will start, but the application will not work. You need to debug and fix the following three critical issues:
The FastAPI backend container is refusing external connections—even from the NGINX container!
- Hint: Look at how the
uvicorncommand is binding its host in theDockerfile. Inside a Docker container, binding tolocalhostor127.0.0.1makes the service unreachable to other containers on the Docker network.
If you navigate to http://localhost right now, you will likely see the default "Welcome to NGINX" page instead of the chat application.
- Hint: Check
docker-compose.yml. How is thenginxcontainer supposed to get access to the static HTML files located in the localfrontend/directory?
Once the UI is visible, the chat app will continuously say "Disconnected" because the WebSocket handshake is failing.
- Hint #1: In
nginx.conf, theproxy_passis attempting to route tolocalhost:8000. Doeslocalhostmean the same thing inside the NGINX container as it does on your laptop? How do containers communicate with each other in a Compose network? - Hint #2: NGINX requires explicit headers to convert standard HTTP traffic into a persistent WebSocket tunnel. Some of the required
Upgradeheaders appear to be missing or disabled.
Submit your finalized, corrected codebase. We will evaluate your submission by executing:
docker-compose up -d --buildIf everything is configured correctly, we should instantly see the UI and be able to open multiple browser tabs at http://localhost to chat back and forth in real-time. Good luck!