Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-sonnet-4-20250514-thinking-32k· AnthropicHugging 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 gpt-4.1-2025-04-14’s answer.
  1. User

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

  2. Claude Assistant

    Here's a devcontainer setup for FastAPI + React development:

    devcontainer.json:

    {
      "name": "FastAPI + React Dev Environment",
      "build": {
        "dockerfile": "Dockerfile"
      },
      "features": {
        "ghcr.io/devcontainers/features/git:1": {},
        "ghcr.io/devcontainers/features/github-cli:1": {}
      },
      "customizations": {
        "vscode": {
          "extensions": [
            "ms-python.python",
            "ms-python.black-formatter",
            "ms-python.flake8",
            "ms-vscode.vscode-typescript-next",
            "bradlc.vscode-tailwindcss",
            "esbenp.prettier-vscode",
            "ms-vscode.vscode-json",
            "ms-python.autopep8"
          ],
          "settings": {
            "python.defaultInterpreterPath": "/usr/local/bin/python",
            "python.formatting.provider": "black",
            "editor.formatOnSave": true,
            "editor.codeActionsOnSave": {
              "source.organizeImports": true
            }
          }
        }
      },
      "forwardPorts": [8000, 3000],
      "portsAttributes": {
        "8000": {
          "label": "FastAPI Backend",
          "onAutoForward": "notify"
        },
        "3000": {
          "label": "React Frontend",
          "onAutoForward": "notify"
        }
      },
      "postCreateCommand": "pip install -r requirements.txt",
      "remoteUser": "vscode"
    }
    

    Dockerfile:

    FROM mcr.microsoft.com/devcontainers/python:1-3.11-bullseye
    
    # Install Node.js
    RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
        && apt-get install -y nodejs
    
    # Install additional system dependencies
    RUN apt-get update && apt-get install -y \
        git \
        curl \
        vim \
        && rm -rf /var/lib/apt/lists/*
    
    # Set working directory
    WORKDIR /workspace
    
    # Install Python dependencies (FastAPI)
    COPY requirements.txt* ./
    RUN if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
    
    # Install global npm packages for React development
    RUN npm install -g create-react-app @vitejs/create-vite
    
    # Create non-root user
    RUN groupadd --gid 1000 vscode \
        && useradd --uid 1000 --gid vscode --shell /bin/bash --create-home vscode \
        && chown -R vscode:vscode /workspace
    
    USER vscode
    

    Sample requirements.txt (create this in your project root):

    fastapi==0.104.1
    uvicorn[standard]==0.24.0
    python-multipart==0.0.6
    pydantic==2.5.0
    python-jose[cryptography]==3.3.0
    passlib[bcrypt]==1.7.4
    python-dotenv==1.0.0
    sqlalchemy==2.0.23
    alembic==1.13.1
    

    Suggested project structure:

    your-project/
    ├── .devcontainer/
    │   ├── devcontainer.json
    │   └── Dockerfile
    ├── backend/
    │   ├── main.py
    │   ├── requirements.txt
    │   └── ...
    ├── frontend/
    │   ├── package.json
    │   ├── src/
    │   └── ...
    └── README.md
    

    To use this setup:

    1. Create a .devcontainer folder in your project root
    2. Add both files to the .devcontainer folder
    3. Create a requirements.txt file in your project root with your Python dependencies
    4. Open your project in VS Code and select "Reopen in Container" when prompted

    The container will expose port 8000 for your FastAPI backend and port 3000 for your React frontend. You can run your FastAPI server with uvicorn main:app --host 0.0.0.0 --port 8000 --reload and your React app with npm start from their respective directories.

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