网站首页 > 技术文章 正文
由于访问 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-05-09 Vite 的实现原理,确实很巧妙(深入vite原理)
- 2025-05-09 微信小程序中使用云函数进行开发(微信小程序创建云函数)
- 2025-05-09 详细讲解npm install命令执行,都干了哪些事情?
- 2025-05-09 如何在 Node.js 中使用 .env 文件管理环境变量 ?
- 2025-05-09 离线环境下运行Vue项目(离线安装vue-cli)
- 2025-05-09 《小鑫发现》之GraphQL框架Prisma
- 2025-05-09 如何写一个webpack插件(一)(webpack常用插件和loader)
- 2025-05-09 Node.js 是怎么找到模块的?(nodejs官方模块)
- 2025-05-09 将 node_modules 目录放入 Git 仓库的优点
- 2025-05-09 在Node.js中处理Zip文件(node.js zip)
- 最近发表
- 标签列表
-
- cmd/c (64)
- c++中::是什么意思 (83)
- 标签用于 (65)
- 主键只能有一个吗 (66)
- c#console.writeline不显示 (75)
- pythoncase语句 (81)
- es6includes (73)
- sqlset (64)
- windowsscripthost (67)
- apt-getinstall-y (86)
- node_modules怎么生成 (76)
- chromepost (65)
- c++int转char (75)
- localstorage.removeitem (74)
- vector线程安全吗 (70)
- & (66)
- java (73)
- org.redisson (64)
- js数组插入 (83)
- gormwherein (64)
- linux删除一个文件夹 (65)
- mac安装java (72)
- eacces (67)
- 查看mysql是否启动 (70)
- 无效的列索引 (74)