Fix format issue

This commit is contained in:
Baohua Yang
2026-02-21 10:19:28 -08:00
parent 063c3f1381
commit 47cfc173a6
45 changed files with 596 additions and 604 deletions

View File

@@ -6,6 +6,8 @@
### 架构概览
如图 10-2 所示Rails PostgreSQL 在同一 Compose 网络中协同工作
```
┌─────────────────────────────────────────────────────────────┐
│ Docker Compose 网络 │
@@ -25,6 +27,8 @@
localhost:3000
```
10-2 Rails + PostgreSQL Compose 架构
### 准备工作
创建项目目录
@@ -35,7 +39,7 @@ $ mkdir rails-docker && cd rails-docker
需要创建三个文件`Dockerfile``Gemfile` `compose.yaml`
### Step 1: 创建 Dockerfile
### 步骤 1创建 Dockerfile
```docker
FROM ruby:3.2
@@ -70,7 +74,7 @@ COPY . /myapp
| `nodejs` | Rails Asset Pipeline 需要 |
| 先复制 Gemfile | 只有依赖变化时才重新 `bundle install` |
### Step 2: 创建 Gemfile
### 步骤 2创建 Gemfile
创建一个初始的 `Gemfile`稍后会被 `rails new` 覆盖
@@ -85,9 +89,9 @@ gem 'rails', '~> 7.1'
$ touch Gemfile.lock
```
### Step 3: 创建 compose.yaml
### 步骤 3创建 compose.yaml
Step 3: 创建 `compose.yaml` 配置如下
配置如下
```yaml
services:
@@ -123,7 +127,7 @@ volumes:
| `depends_on: db` | 确保数据库先启动 |
| `DATABASE_URL` | Rails 12-factor 风格的数据库配置 |
### Step 4: 生成 Rails 项目
### 步骤 4生成 Rails 项目
使用 `docker compose run` 生成项目骨架
@@ -149,7 +153,7 @@ compose.yaml bin db public
> **Linux 用户**如遇权限问题执行 `sudo chown -R $USER:$USER .`
### Step 5: 重新构建镜像
### 步骤 5重新构建镜像
由于生成了新的 Gemfile需要重新构建镜像以安装完整依赖
@@ -157,7 +161,7 @@ compose.yaml bin db public
$ docker compose build
```
### Step 6: 配置数据库连接
### 步骤 6配置数据库连接
修改 `config/database.yml`
@@ -181,7 +185,7 @@ production:
> 💡 使用 `DATABASE_URL` 环境变量配置数据库符合 12-factor 应用原则便于在不同环境间切换
### Step 7: 启动应用
### 步骤 7启动应用
运行以下命令
@@ -201,7 +205,7 @@ web-1 | Puma starting in single mode...
web-1 | * Listening on http://0.0.0.0:3000
```
### Step 8: 创建数据库
### 步骤 8创建数据库
在另一个终端执行