# 如何自定义 Docked？

- Link: https://www.ixiqin.com/2023/12/20/how-to-customize-docked/
- Published: 2023-12-20T10:00:00+08:00
- Author: 白宦成

文章目录

 [Toggle](https://www.ixiqin.com/2023/12/20/how-to-customize-docked/#)

 * [Fork Docked 项目](https://www.ixiqin.com/2023/12/20/how-to-customize-docked/#fork_docked_%e9%a1%b9%e7%9b%ae)
 * [修改 Dockerfile](https://www.ixiqin.com/2023/12/20/how-to-customize-docked/#%e4%bf%ae%e6%94%b9_dockerfile)
    - [修改 Ruby 版本](https://www.ixiqin.com/2023/12/20/how-to-customize-docked/#%e4%bf%ae%e6%94%b9_ruby_%e7%89%88%e6%9c%ac)
    - [修改 Node 版本](https://www.ixiqin.com/2023/12/20/how-to-customize-docked/#%e4%bf%ae%e6%94%b9_node_%e7%89%88%e6%9c%ac)
 * [修改编译脚本，上传镜像](https://www.ixiqin.com/2023/12/20/how-to-customize-docked/#%e4%bf%ae%e6%94%b9%e7%bc%96%e8%af%91%e8%84%9a%e6%9c%ac%ef%bc%8c%e4%b8%8a%e4%bc%a0%e9%95%9c%e5%83%8f)
 * [修改 Readme](https://www.ixiqin.com/2023/12/20/how-to-customize-docked/#%e4%bf%ae%e6%94%b9_readme)
 * [总结](https://www.ixiqin.com/2023/12/20/how-to-customize-docked/#%e6%80%bb%e7%bb%93)

我在之前的文章 [使用 Docked Rails CLI 简化 Rails 的开发](https://www.ixiqin.com/2023/12/18/simplify-rails-development-using-docked-rails-cli/)
中介绍了 Ruby on Rails 的 Docked 程序，并提供了一个我自己的定制版本。

这里来和大家说一下怎么自定义 Docked 镜像，从而构建一个适合你自己的镜像。

## Fork Docked 项目

At first ，你需要 Fork Rails 官方的项目

[https://github.com/rails/docked](https://github.com/rails/docked)

Fork 项目到你自己的名下后，你可以修改一下他的名字，改成适合你自己习惯的名字（比如
我就改成 Runs 了，Docked 对我来说太容易打成 Docker 了）。

## 修改 Dockerfile

Docked 最核心的其实就是 Dockerfile ，你可以修改你 Fork 来的项目，并在 Dockerfile
当中添加必要的依赖，引入新的资料等。

比如，[https://github.com/bestony/runs/commit/d930a5d6fc389cb6fa8e9f7c41947d01b000da95](https://github.com/bestony/runs/commit/d930a5d6fc389cb6fa8e9f7c41947d01b000da95)
这个 Commit 就是为了在 Dockerfile 当中添加 PGSQL 的配置，以实现在使用 `rails new`
命令时，可以选用 PGSQL as DB Backend。

### 修改 Ruby 版本

可参考：[https://github.com/bestony/runs/commit/31fabe5f914d931834b0e12797b14d76bf56d162](https://github.com/bestony/runs/commit/31fabe5f914d931834b0e12797b14d76bf56d162)

### 修改 Node 版本

可参考：[https://github.com/bestony/runs/commit/5969cc4ee5c0bf8503ebdab5664f365b6719843e](https://github.com/bestony/runs/commit/5969cc4ee5c0bf8503ebdab5664f365b6719843e)

## 修改编译脚本，上传镜像

修改完成 Dockerfile 后，接下来你需要修改 Docker镜像产物，以便于你自己在实际使用过程
中，直接使用你自己的 Docker 镜像。

修改 [https://github.com/bestony/runs/blob/160fe165db7abecc3229be417b15473dcd3aec9f/.github/workflows/docker-publish.yml#L41](https://github.com/bestony/runs/blob/160fe165db7abecc3229be417b15473dcd3aec9f/.github/workflows/docker-publish.yml#L41)
的 tags 为你自己的，格式为 `ghcr.io/{你的 ID}/{你的仓库名}`。

修改好之后，只需要提交 Commit ，等待 Github Action 的自动构建即可。

## 修改 Readme

镜像构建结束，你只需要修改 Readme 中的安装配置命令，这样在后续使用时就不用自己再
修改了。重点修改的内容包括 ailas、镜像名以及底部的启动命令。

![](https://files.ixiqin.com/2023/12/23062304/d2b5ca33bd970f64a6301fa75ae2eb22-1024x507.
png)

## 总结

通过对 Docked 的简单修改，可以实现快速构建一个属于你自己的开发环境命令，帮你优化
自己的工作流。
