Add Dockerfile.fullstack
- single container for nextjs/backend
#1433
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
frontend/nextjs
app (exposing port 3000) and the python uvicorn backend (exposing port 8000).HOST
,PORT
, andNEXTJS_PORT
to configure internals.Build and run
docker buildx build -f Dockerfile.fullstack . --tag assafelovic/gpt-researcher-fullstack-test docker run -p 3000:3000 -p 8000:8000 --env-file .env assafelovic/gpt-researcher-fullstack-test
EDIT: Thank you for merging #1411 -- I'll see if I can submit another PR adding this to its workflow (and removing the MCP build) this weekend
AI-written explanations on the changes:
PR: Add
Dockerfile.fullstack
for Unified Frontend and Backend DeploymentOverview
This PR introduces a new
Dockerfile.fullstack
that builds and serves both the Next.js frontend and the FastAPI (uvicorn) backend in a single Docker container. This approach streamlines deployment and simplifies development or production environments where maintaining separate containers is unnecessary or impractical.Key Components and Workflow
1. Multi-Stage Build
2. Supervisord: Unified Process Management
PORT
)NEXT_INTERNAL_PORT
).NEXT_PORT
).Both the
uvicorn
backend and thenextjs
app are accessible on NEXT_PORT (3000). This was done so reverse proxies outside the container would work properly. Example:Without the
nginx
solution, Traefik would need the following lines to actually work properly:This setup ensures all three processes are started together and automatically restarted if any of them crash, which is crucial in a Docker environment where by default only one foreground process is allowed.
3. Nginx: Reverse Proxy and Routing
Nginx serves several roles:
/outputs
,/reports
,/ws
) to the FastAPI backend.This is needed because neither Next.js nor FastAPI can efficiently serve both frontend and API routes from a shared public port, nor handle WebSockets and static assets as robustly as nginx.
Usage
docker build -f Dockerfile.fullstack -t gptr:fullstack .
Why This Approach?
supervisord
ensures all core processes are running, or restarts them if they fail.nginx
provides a production-grade reverse proxy, static asset delivery, and WebSocket support/routing