Fix and update

This commit is contained in:
baohua
2026-02-09 11:34:35 -08:00
parent 784c989789
commit bb94a9f617
136 changed files with 2146 additions and 262 deletions

View File

@@ -6,6 +6,8 @@
### 架构概览
具体内容如下
```
┌─────────────────────────────────────────────────────────────┐
│ Docker Compose 网络 │
@@ -37,23 +39,29 @@ $ mkdir rails-docker && cd rails-docker
### Step 1: 创建 Dockerfile
具体内容如下
```docker
FROM ruby:3.2
## 安装系统依赖
RUN apt-get update -qq && \
apt-get install -y build-essential libpq-dev nodejs && \
rm -rf /var/lib/apt/lists/*
## 设置工作目录
WORKDIR /myapp
## 先复制 Gemfile利用缓存加速构建
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
## 复制应用代码
COPY . /myapp
```
@@ -83,6 +91,8 @@ $ touch Gemfile.lock
### Step 3: 创建 docker-compose.yml
Step 3: 创建 docker-compose.yml 配置如下
```yaml
services:
db:
@@ -176,6 +186,8 @@ production:
### Step 7: 启动应用
运行以下命令
```bash
$ docker compose up
```
@@ -206,20 +218,27 @@ Created database 'myapp_test'
### 常用开发命令
运行以下命令
```bash
## 数据库迁移
$ docker compose exec web rails db:migrate
## Rails 控制台
$ docker compose exec web rails console
## 运行测试
$ docker compose exec web rails test
## 生成脚手架
$ docker compose exec web rails generate scaffold Post title:string body:text
## 进入容器 Shell
$ docker compose exec web bash
```