执行bundle install返回非零码10,请求排查Rails项目部署问题
Hey there, let's break down this issue step by step. The exit code 10 from bundle install usually points to problems with dependency resolution, missing system libraries, or permission mismatches. Let's go through your setup to fix this:
1. Fix the Rails project creation command
Your initial Docker command has a couple of issues that might be causing permission or project structure problems:
- The
cd webappat the end runs on your host machine, not inside the container (since the container exits immediately after creating the project). - The
rails new webappcreates a subdirectorywebappinside the mounted volume, which can lead to path confusion later.
Update your command to create the project directly in the host's webapp directory:
# First create an empty directory on your host mkdir -p webapp # Run the Rails new command to populate this directory docker run -it --rm --user "$(id -u):$(id -g)" \ -v "$PWD/webapp":/usr/src/app -w /usr/src/app \ rails rails new --skip-bundle --api --database postgresql .
2. Resolve bundle install dependencies
Exit code 10 often happens when gems like pg (PostgreSQL adapter) can't compile because system libraries are missing. The official Rails Docker image doesn't include PostgreSQL development tools by default.
Install missing dependencies first:
# Run a root shell in the Rails image to install system libraries docker run -it --rm --user root -v "$PWD/webapp":/usr/src/app -w /usr/src/app rails bash # Inside the container, run: apt-get update && apt-get install -y libpq-dev postgresql-client exit
Now run bundle install correctly:
docker run -it --rm --user "$(id -u):$(id -g)" \ -v "$PWD/webapp":/usr/src/app -w /usr/src/app \ rails bundle install
3. Fix Nginx/Passenger configuration
Your webapp.conf has incorrect paths that will break Passenger's ability to find your Rails app:
- The
rootdirective must point to the public directory of your Rails app (not your host's project root). - The
passenger_rubypath must match the Ruby executable path inside your container (the official Rails image uses/usr/local/bin/ruby, not/usr/bin/ruby2.4).
Update webapp.conf to:
server { listen 80; server_name _; root /usr/src/app/public; # Point to Rails' public folder inside the container passenger_enabled on; passenger_user app; passenger_ruby /usr/local/bin/ruby; # Verify with `docker run --rm rails which ruby` }
4. Validate environment variables
In rails-env.conf, make sure your DATABASE_URL is properly formatted for your PostgreSQL setup. It should look something like:
env DATABASE_URL=postgres://db_user:db_password@postgres_host:5432/webapp_production;
Double-check that the PostgreSQL host, credentials, and database name match your actual database service configuration.
内容的提问来源于stack exchange,提问作者tomatito

