-
Notifications
You must be signed in to change notification settings - Fork 610
Description
Description
The fastapi service defined in docker-compose.yaml does not have a ports section to map the container's port (8080, as defined in Dockerfile.webserver) to a host port. This makes the FastAPI service inaccessible from the host machine.
Location
docker-compose.yaml - fastapi service definition
Severity
Impact
- API is inaccessible: Developers cannot interact with or test the FastAPI service when running via Docker Compose
- Poor developer experience: Confusing for new contributors who expect the API to be accessible
- Testing limitations: Cannot run integration tests against the API locally
- Documentation mismatch: If documentation mentions accessing the API, it won't work as described
Current Configuration
services:
fastapi:
build:
context: .
dockerfile: Dockerfile.webserver
environment:
- SOME_ENV_VAR=value
# ❌ Missing ports section!Expected Behavior
When running docker-compose up fastapi, developers should be able to access the API at http://localhost:8080.
Actual Behavior
The FastAPI service runs inside the container but is not accessible from the host machine. Attempting to access http://localhost:8080 results in a connection refused error.
Steps to Reproduce
- Run
docker-compose up fastapi - Try to access the API:
curl http://localhost:8080 - Connection fails because port is not mapped
- Check running containers:
docker psshows the container but no port mapping
Proposed Solution
Add a ports section to the fastapi service definition:
services:
fastapi:
build:
context: .
dockerfile: Dockerfile.webserver
ports:
- "8080:8080" # Map host port 8080 to container port 8080
environment:
- SOME_ENV_VAR=valueAlternative Solutions
Option 1: Use a different host port
If port 8080 is commonly used, consider mapping to a different host port:
ports:
- "8000:8080" # Access API at localhost:8000Option 2: Document the intended usage
If the FastAPI service is only meant to be accessed by other containers in the Docker network, add a comment explaining this:
fastapi:
# Note: This service is only accessible within the Docker network
# Other services can access it at http://fastapi:8080
build:
context: .
dockerfile: Dockerfile.webserverAdditional Context
The Dockerfile.webserver runs the application on port 8080:
CMD ["opentelemetry-instrument", "uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8080"]This port needs to be exposed in docker-compose.yaml for local development.
Verification
After applying the fix, verify with:
# Start the service
docker-compose up fastapi
# In another terminal, test the API
curl http://localhost:8080/docs # Should show FastAPI docs
curl http://localhost:8080/health # Should return health status