网站首页 > 技术文章 正文
由于访问 https://docs.docker.com/ 文档慢,直接本地部署官方文档
如果不想执行以下操作,也可以直接使用官方文档仓库地址提供的 Dockerfile 和 compose.yaml 进行操作
以下操作环境为Windows系统,根据 Dockerfile 相关操作来生成 html 页面
Dockerfile地址:
https://github.com/docker/docs/blob/main/Dockerfilecompose.yaml地址:
https://github.com/docker/docs/blob/main/compose.yaml
1、安装 go
下载地址:https://go.dev/dl/
当前版本:1.22.2
2、安装 nodejs
下载地址:https://nodejs.org/en/download/package-manager
当前node版本:20.12.2
当前npm版本:10.5.0
3、安装 hugo
hugo官网:https://gohugo.io/
下载地址:https://github.com/gohugoio/hugo/releases/tag/v0.133.0
当前版本:0.133.0
4、操作命令
# 根据 package.json 文件下载依赖到 node_modules 目录
npm install
# 生成 html 页面,指定目录为 out,网站url为空
hugo --minify -d out -b ""
# 生成 pagefind,指定源文件目录 out,指定输出文件目录 pagefind
npx pagefind@v1.1.0 --site "out" --output-path "pagefind"
5、复制文件
html页面:out 目录
网页内容查询文件:pagefind 目录
示例:
可以将 out 目录的内容复制到 xxx/public下,然将 pagefind 目录复制到 public 目录下
ps:也就是 pagefind 目录下的文件在 out 目录下
6、部署
可以使用不同方式部署
6.1、使用nginx搭建静态服务
如使用phpstudy、宝塔等软件
6.2、编写文件服务
1)在 步骤5 所在目录创建 main.go 文件,编写 http 服务
2)然后执行 `go run main.go`
3)浏览器访问 `http://127.0.0.1:1234/`
其中main.go内容为:
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strings"
)
// 如有错误,请根据实际情况修改下面代码
func main() {
// http.Handle("/", http.FileServer(http.Dir("/")))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
uri := r.RequestURI
// 移除问号
pos := strings.LastIndex(uri, "?")
if pos > -1 {
uri = uri[:pos]
}
// 以 / 结尾,自动追加 index.html
if strings.HasSuffix(uri, "/") {
uri += "index.html"
}
// 获取文件绝对路径
curPwd, _ := os.Getwd()
absPath := filepath.Join(curPwd, "\\", uri)
absPath = filepath.FromSlash(absPath)
// 读取文件内容
b, err := ioutil.ReadFile(absPath)
if err != nil {
w.Write(nil)
return
}
// 显示异常,请添加相应的content-type
contentTypeMap := map[string]string{
// ".html": "text/html",
".css": "text/css",
".js": "application/javascript",
".ico": "image/x-icon",
".svg": "image/svg+xml",
// ".webp": "image/webp",
".json": "application/json",
}
pos = strings.LastIndex(absPath, ".")
suffix := absPath[pos:]
if v, ok := contentTypeMap[suffix]; ok {
w.Header().Add("content-type", v)
}
w.Write(b)
})
fmt.Println("http server running on http://127.0.0.1:1234/")
http.ListenAndServe("0.0.0.0:1234", nil)
}
6.3、其他方式
略
7、启动服务
8、浏览器访问
9、相关代码
编译生成的代码:
https://gitcode.net/janthinasnail/docs-docker/-/tree/build-on-windows
docker文档(可以用于部署):
https://gitcode.net/janthinasnail/docs-docker/-/tree/pages-on-windows
源文档地址:https://docs.docker.com/
猜你喜欢
- 2025-08-01 基于Springboot + vue实现的社团管理系统
- 2025-08-01 前端开发如何用Mock.js进行数据接口模拟
- 2025-08-01 使用vite为vue项目配置@别名
- 2025-08-01 基于Springboot + vue3实现的教务管理系统
- 2025-08-01 gulp前端自动化构建入门指南(一)
- 2025-08-01 快速搭建页面:一款开源可视化拖拽工具
- 2025-08-01 深入 npm 模块安装机制
- 2025-08-01 【推荐】一个基于 Vue 开源的可视化页面生成工具,前端开发利器
- 2025-08-01 告别node_modules黑洞:团队迁移pnpm节省50G磁盘空间实战指南
- 2025-08-01 告别node_modules黑洞!pnpm凭什么吊打npm和yarn?
- 最近发表
- 标签列表
-
- cmd/c (90)
- c++中::是什么意思 (84)
- 标签用于 (71)
- 主键只能有一个吗 (77)
- c#console.writeline不显示 (95)
- pythoncase语句 (88)
- es6includes (74)
- sqlset (76)
- apt-getinstall-y (100)
- node_modules怎么生成 (87)
- chromepost (71)
- flexdirection (73)
- c++int转char (80)
- mysqlany_value (79)
- static函数和普通函数 (84)
- el-date-picker开始日期早于结束日期 (76)
- js判断是否是json字符串 (75)
- c语言min函数头文件 (77)
- asynccallback (87)
- localstorage.removeitem (74)
- vector线程安全吗 (70)
- java (73)
- js数组插入 (83)
- mac安装java (72)
- 无效的列索引 (74)