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

执行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 webapp at the end runs on your host machine, not inside the container (since the container exits immediately after creating the project).
  • The rails new webapp creates a subdirectory webapp inside 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 root directive must point to the public directory of your Rails app (not your host's project root).
  • The passenger_ruby path 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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:50:05