You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:无法通过Docker Compose结合Wodby Node镜像本地运行Gatsby站点

Fixing 404 Error for Gatsby in Wodby Docker4WordPress Setup

Let’s walk through troubleshooting and fixing this 404 issue — I remember struggling with similar Docker routing problems when I first set up Gatsby with a WordPress backend, so let’s get your site up and running.

Step 1: Verify Gatsby is Actually Running in the Node Container

First, we need to rule out whether the problem is with Gatsby itself or the Docker/Traefik routing.

  • Check the Node container logs for startup errors:
    docker logs ${PROJECT_NAME}_node
    
    Look for lines like success compiled successfully (that means Gatsby started correctly) or errors like npm ERR! (dependency issues) or port 3000 already in use.
  • If logs look unclear, jump into the container to inspect directly:
    docker exec -it ${PROJECT_NAME}_node bash
    
    Once inside, run curl localhost:3000 — if you get a 404 here too, the problem is with your Gatsby setup, not Docker routing. Double-check that:
    • Your gatsby_site folder is mounted correctly (run ls /app to confirm package.json, gatsby-config.js exist here)
    • npm install completed without errors (look for a node_modules folder in /app)
    • Your Gatsby config points to the correct WordPress API URL (use the Docker service name http://nginx/wp-json or your local WordPress domain like http://wordpress.local/wp-json)

Step 2: Fix Traefik Routing & Local DNS

If Gatsby runs fine inside the container but you get a 404 externally, the issue is with Traefik or your local DNS.

  • Update your local hosts file:
    Traefik uses the Host(node.${PROJECT_BASE_URL}) rule to route traffic. If your PROJECT_BASE_URL is, say, wordpress.local, add this line to your hosts file:
    127.0.0.1 node.wordpress.local
    
    (On Windows: C:\Windows\System32\drivers\etc\hosts; on Mac/Linux: /etc/hosts — you’ll need admin rights to edit this.)
  • Check Traefik’s service recognition:
    If you enabled the Traefik dashboard (uncomment the 8080:8080 port in the traefik service), visit localhost:8080 and look for the node.${PROJECT_BASE_URL} router and corresponding service. If it’s missing, restart the Traefik container to refresh:
    docker restart ${PROJECT_NAME}_traefik
    

Step 3: Tweak Your Docker Compose Node Service

Here’s an updated version of your node service with fixes for common issues:

node:
  image: wodby/node:$NODE_TAG
  container_name: "${PROJECT_NAME}_node"
  working_dir: /app
  restart: unless-stopped # Auto-restart if the container crashes
  labels:
    - "traefik.http.services.${PROJECT_NAME}_node.loadbalancer.server.port=3000"
    - "traefik.http.routers.${PROJECT_NAME}_node.rule=Host(`node.${PROJECT_BASE_URL}`)"
  ports:
    - "3000:3000" # Add this to test directly without Traefik
  expose:
    - "3000"
  volumes:
    - ./gatsby_site:/app # Double-check this path matches your project structure!
  command: sh -c 'npm install && npm run develop' # Use `develop` for hot reloading (Gatsby's default dev command)
  • Using npm run develop instead of start ensures Gatsby runs in development mode with hot reloading (the default start command is for production builds, which require a prior gatsby build).
  • The ports mapping lets you test Gatsby directly at localhost:3000 to bypass Traefik — if this works, you know your routing is the main issue.

Step 4: Final Testing

  1. Restart all services to apply changes:
    docker-compose down && docker-compose up -d
    
  2. First test direct access: Visit localhost:3000 — if this loads Gatsby, great! Now try the Traefik route (node.your-project-url.local).
  3. If Traefik still returns 404, check the Traefik logs for routing errors:
    docker logs ${PROJECT_NAME}_traefik
    

Quick Troubleshooting Checklist

  • Gatsby container has no startup errors (check logs)
  • gatsby_site files are correctly mounted to /app in the node container
  • Local hosts file includes node.${PROJECT_BASE_URL} pointing to 127.0.0.1
  • Traefik recognizes the node service (check dashboard if enabled)
  • Gatsby is using develop mode (not production start without a build)

内容的提问来源于stack exchange,提问作者vasilis 123

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 04:27:40