Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-2025-04-14· OpenAIHugging Face LMArena Human Preference 140K

can you write a devcontainer.json and a dockerfile for fastapi + react?

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-sonnet-4-20250514-thinking-32k’s answer.
  1. User

    can you write a devcontainer.json and a dockerfile for fastapi + react?

  2. Assistant

    Absolutely! Below is a basic setup for a VS Code Dev Container that supports both FastAPI (Python backend) and React (frontend) development. This setup uses a multi-service approach with Docker Compose, which is the recommended way to handle both backend and frontend in development.


    1. devcontainer.json

    This file tells VS Code how to start your development environment.

    {
      "name": "FastAPI + React DevContainer",
      "dockerComposeFile": [
        "docker-compose.yml"
      ],
      "service": "backend",
      "workspaceFolder": "/workspace",
      "settings": {
        "terminal.integrated.defaultProfile.linux": "bash"
      },
      "extensions": [
        "ms-python.python",
        "ms-python.vscode-pylance",
        "esbenp.prettier-vscode",
        "dbaeumer.vscode-eslint"
      ],
      "postCreateCommand": "pip install -r requirements.txt"
    }
    

    2. docker-compose.yml

    This file defines two services: backend (FastAPI) and frontend (React).

    version: '3.8'
    services:
      backend:
        build:
          context: .
          dockerfile: Dockerfile.backend
        volumes:
          - .:/workspace
        ports:
          - "8000:8000"
        command: uvicorn app.main:app --host 0.0.0.0 --reload
      frontend:
        build:
          context: ./frontend
          dockerfile: Dockerfile.frontend
        volumes:
          - ./frontend:/app
        ports:
          - "3000:3000"
        command: npm start
    

    3. Dockerfile.backend (FastAPI)

    FROM python:3.11-slim
    
    WORKDIR /workspace
    
    COPY requirements.txt .
    RUN pip install --no-cache-dir -r requirements.txt
    
    COPY ./app ./app
    
    CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--reload"]
    

    Example requirements.txt:

    fastapi
    uvicorn[standard]
    

    4. frontend/Dockerfile.frontend (React)

    FROM node:20
    
    WORKDIR /app
    
    COPY package.json package-lock.json ./
    RUN npm install
    
    COPY . .
    
    CMD ["npm", "start"]
    

    5. Project Structure Example

    .
    ├── app/
    │   └── main.py
    ├── frontend/
    │   ├── package.json
    │   ├── package-lock.json
    │   └── src/
    ├── requirements.txt
    ├── Dockerfile.backend
    ├── frontend/Dockerfile.frontend
    ├── docker-compose.yml
    └── .devcontainer/
        └── devcontainer.json
    

    6. Notes

    • FastAPI code goes in the app/ directory.
    • React code goes in the frontend/ directory.
    • You can add more Python or Node dependencies as needed.
    • VS Code will attach to the backend container by default, but you can open terminals in either container.

    Let me know if you want a single-container setup or more customization!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.