如何在生产环境执行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:
First, we need to confirm if your containers are running properly and catch any errors:
- Open a new terminal and run
sudo docker-compose psto check the status of all services (web, db, redis, etc.). If any service showsExitedorRestarting, that's a red flag. - Pull the live logs for the web container—this is where most issues show up:
Look for errors like failed database connections, missingsudo docker-compose logs -f web.envvariables, port conflicts, or asset precompilation failures.
FarmBot's web service needs to be accessible from outside the container:
- Open your
docker-compose.ymlfile and check theportssection 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 withhttp://your-ip:3000(not just the IP). - Check Ubuntu's local firewall (ufw):
Make sure the target port (80 or 3000) is allowed. If not, add a rule:sudo ufw statussudo 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.
Rails production mode relies on correct environment settings:
- Double-check your
.envfile: confirmRAILS_ENV=productionis set, and that database credentials (likePOSTGRES_HOST,POSTGRES_USER,POSTGRES_PASSWORD) match what's defined in yourdocker-compose.ymlfor 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(notlocalhost) in its config file (e.g.,config/puma.rb).localhostwould block external access to 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:
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:curl http://localhost:3000bundle exec rails console production # Try a simple query like: User.first (if the model exists)
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

