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

如何在生产环境执行docker-compose up启动DigitalOcean上的FarmBot Web API

Hey there! Let's figure out why your FarmBot Web API isn't loading when you visit your DigitalOcean server's IP after running sudo docker-compose up. I'll walk you through practical troubleshooting steps:

1. Check Container Status & Logs First

First, we need to confirm if your containers are running properly and catch any errors:

  • Open a new terminal and run sudo docker-compose ps to check the status of all services (web, db, redis, etc.). If any service shows Exited or Restarting, that's a red flag.
  • Pull the live logs for the web container—this is where most issues show up:
    sudo docker-compose logs -f web
    
    Look for errors like failed database connections, missing .env variables, port conflicts, or asset precompilation failures.
2. Verify Port Mapping & Firewall Rules

FarmBot's web service needs to be accessible from outside the container:

  • Open your docker-compose.yml file and check the ports section for the web service. It should look something like "80:3000" (maps container port 3000 to host port 80) or "3000:3000". If it's the latter, you'll need to access your app with http://your-ip:3000 (not just the IP).
  • Check Ubuntu's local firewall (ufw):
    sudo ufw status
    
    Make sure the target port (80 or 3000) is allowed. If not, add a rule:
    sudo ufw allow 80/tcp  # or 3000/tcp
    sudo ufw reload
    
  • Don't forget DigitalOcean's cloud firewall! Head to your DO control panel, check the firewall rules for your droplet, and ensure the same port is open to incoming traffic. This is a super common oversight.
3. Validate Production Config & .env Variables

Rails production mode relies on correct environment settings:

  • Double-check your .env file: confirm RAILS_ENV=production is set, and that database credentials (like POSTGRES_HOST, POSTGRES_USER, POSTGRES_PASSWORD) match what's defined in your docker-compose.yml for the db service.
  • Re-run asset precompilation inside the container (precompiling on the host might not work due to environment differences):
    sudo docker-compose exec web bundle exec rake assets:precompile RAILS_ENV=production
    
  • Ensure your Rails server (Puma/Unicorn) is listening on 0.0.0.0 (not localhost) in its config file (e.g., config/puma.rb). localhost would block external access to the container.
4. Test the App Inside the Container

If external access fails, check if the app works internally first:

  • Enter the web container's shell:
    sudo docker-compose exec web bash
    
  • Test the app with curl:
    curl http://localhost:3000
    
    If this fails, the issue is with the app itself (e.g., incomplete migrations, missing gems). You can also test database connectivity via the Rails console:
    bundle exec rails console production
    # Try a simple query like: User.first (if the model exists)
    
5. Restart Containers & Clear Stale Cache

Sometimes stale containers or cached assets cause issues:

  • Stop all containers:
    sudo docker-compose down
    
  • Clean up unused Docker resources (safe for most cases):
    sudo docker system prune -f
    
  • Rebuild and restart the stack to ensure all dependencies are fresh:
    sudo docker-compose up --build
    

If you're still stuck, share the key error lines from your web container logs—they'll help pinpoint the exact problem.

内容的提问来源于stack exchange,提问作者Haseeb Ahmad

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.13 09:24:31