Remove blank lines after code block markers

This commit is contained in:
yeasy
2026-03-21 22:36:09 -07:00
parent 312f8fea42
commit 9ac19d79ee
132 changed files with 0 additions and 1517 deletions

View File

@@ -30,7 +30,6 @@ flowchart TD
Browser["localhost:3000"]
Port3000 --> Browser
```
11-2Rails + PostgreSQL Compose 架构
### 11.7.2 准备工作
@@ -40,7 +39,6 @@ flowchart TD
```bash
$ mkdir rails-docker && cd rails-docker
```
需要创建三个文件`Dockerfile``Gemfile` `compose.yaml`
### 11.7.3 步骤 1创建 Dockerfile
@@ -68,7 +66,6 @@ RUN bundle install
COPY . /myapp
```
**配置说明**
| 指令 | 作用 |
@@ -86,13 +83,11 @@ COPY . /myapp
source 'https://rubygems.org'
gem 'rails', '~> 7.1'
```
创建空的 `Gemfile.lock`
```bash
$ touch Gemfile.lock
```
### 11.7.5 步骤 3创建 compose.yaml
配置如下
@@ -121,7 +116,6 @@ services:
volumes:
postgres_data:
```
**配置详解**
| 配置项 | 说明 |
@@ -138,7 +132,6 @@ volumes:
```bash
$ docker compose run --rm web rails new . --force --database=postgresql --skip-bundle
```
**命令解释**
- `--rm`执行后删除临时容器
@@ -155,7 +148,6 @@ Gemfile.lock README.md app config.ru log
compose.yaml bin db public
```
> **Linux 用户**如遇权限问题执行 `sudo chown -R $USER:$USER .`
### 11.7.7 步骤 5重新构建镜像
@@ -165,7 +157,6 @@ compose.yaml bin db public
```bash
$ docker compose build
```
### 11.7.8 步骤 6配置数据库连接
修改 `config/database.yml`
@@ -187,7 +178,6 @@ test:
production:
<<: *default
```
> 💡 使用 `DATABASE_URL` 环境变量配置数据库符合 12-factor 应用原则便于在不同环境间切换
### 11.7.9 步骤 7启动应用
@@ -195,7 +185,6 @@ production:
```bash
$ docker compose up
```
输出示例
```bash
@@ -207,7 +196,6 @@ web-1 | => Run `bin/rails server --help` for more startup options
web-1 | Puma starting in single mode...
web-1 | * Listening on http://0.0.0.0:3000
```
### 11.7.10 步骤 8创建数据库
在另一个终端执行
@@ -217,13 +205,11 @@ $ docker compose exec web rails db:create
Created database 'myapp_development'
Created database 'myapp_test'
```
访问 http://localhost:3000 查看 Rails 欢迎页面。
### 11.7.11 常用开发命令
```bash
## 数据库迁移
$ docker compose exec web rails db:migrate
@@ -244,7 +230,6 @@ $ docker compose exec web rails generate scaffold Post title:string body:text
$ docker compose exec web bash
```
### 11.7.12 常见问题
#### Q数据库连接失败
@@ -255,7 +240,6 @@ $ docker compose exec web bash
$ docker compose ps
$ docker compose logs db
```
#### Qserver.pid 文件导致启动失败
错误信息`A server is already running`
@@ -265,7 +249,6 @@ $ docker compose logs db
```bash
$ docker compose exec web rm -f tmp/pids/server.pid
```
#### QGem 安装失败
可能需要更新 bundler 或清理缓存
@@ -273,7 +256,6 @@ $ docker compose exec web rm -f tmp/pids/server.pid
```bash
$ docker compose run --rm web bundle update
```
### 11.7.13 开发 vs 生产
| 配置项 | 开发环境 | 生产环境 |