求助:无法通过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:
Look for lines likedocker logs ${PROJECT_NAME}_nodesuccess compiled successfully(that means Gatsby started correctly) or errors likenpm ERR!(dependency issues) orport 3000 already in use. - If logs look unclear, jump into the container to inspect directly:
Once inside, rundocker exec -it ${PROJECT_NAME}_node bashcurl localhost:3000— if you get a 404 here too, the problem is with your Gatsby setup, not Docker routing. Double-check that:- Your
gatsby_sitefolder is mounted correctly (runls /appto confirmpackage.json,gatsby-config.jsexist here) npm installcompleted without errors (look for anode_modulesfolder in/app)- Your Gatsby config points to the correct WordPress API URL (use the Docker service name
http://nginx/wp-jsonor your local WordPress domain likehttp://wordpress.local/wp-json)
- Your
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 theHost(node.${PROJECT_BASE_URL})rule to route traffic. If yourPROJECT_BASE_URLis, say,wordpress.local, add this line to your hosts file:
(On Windows:127.0.0.1 node.wordpress.localC:\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 the8080:8080port in the traefik service), visitlocalhost:8080and look for thenode.${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 developinstead ofstartensures Gatsby runs in development mode with hot reloading (the defaultstartcommand is for production builds, which require a priorgatsby build). - The
portsmapping lets you test Gatsby directly atlocalhost:3000to bypass Traefik — if this works, you know your routing is the main issue.
Step 4: Final Testing
- Restart all services to apply changes:
docker-compose down && docker-compose up -d - First test direct access: Visit
localhost:3000— if this loads Gatsby, great! Now try the Traefik route (node.your-project-url.local). - 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_sitefiles are correctly mounted to/appin 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
developmode (not productionstartwithout a build)
内容的提问来源于stack exchange,提问作者vasilis 123
相关产品推荐
相关产品推荐

