本地部署docker文档

由于访问 https://docs.docker.com/ 文档慢,直接本地部署官方文档

如果不想执行以下操作,也可以直接使用官方文档仓库地址提供的 Dockerfile 和 compose.yaml 进行操作

以下操作环境为Windows系统,根据 Dockerfile 相关操作来生成 html 页面

步骤1~3可以参考:搭建自己的wiki知识库【转】_wiki搭建-CSDN博客

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

Go 复制代码
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内容为:

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、相关代码

编译生成的代码:build-on-windows · janthinasnail / Docs Docker · GitCode

docker文档(可以用于部署):pages-on-windows · janthinasnail / Docs Docker · GitCode

源文档地址:https://docs.docker.com/

相关推荐
wno7042 小时前
Nginx禁止蜘蛛程序访问
运维·nginx
csdn_aspnet3 小时前
如何使用 Docker 设置 PostgreSQL
运维·数据库·docker·postgresql·容器
jipinxiaofeihua4 小时前
(文章8) 05章-C++泛型编程(下)
linux·运维·网络
赵文宇(温玉)6 小时前
Docker离线安装
运维·docker·容器
进击的荆棘7 小时前
Linux网络——传输层协议UDP
linux·运维·服务器·网络·udp
Android系统攻城狮8 小时前
FFmpeg深度解析之av_bsf_get_by_name:如何查找码流过滤器?(七十九)
linux·运维·ffmpeg·音视频进阶·ffmpeg音视频
Decay__9 小时前
PostgreSQL 监控体系构建 —— postgres_exporter + Prometheus + Grafana 全栈实战
运维·数据库·sql·postgresql
Decay__10 小时前
PostgreSQL 告警与自动化运维 —— 告警分级收敛、Webhook、定时巡检、脚本库
运维·数据库·sql·postgresql
程序员agions12 小时前
Docker Compose 生产环境配置记录
运维·docker·容器
郝学胜-神的一滴12 小时前
Effective Python 条款45:巧用属性注解平滑升级类属性
运维·开发语言·数据库·python·网络协议·numpy