gitbook安裝與使用,並使用docker部署


本文簡單介紹如何安裝並使用gitbook,最后如何使用docker構建書籍鏡像。

1. 前置條件

需要Nodejs環境,安裝npm,國內用戶再安裝cnpm

npm install -g cnpm --registry=https://registry.npm.taobao.org

2. 安裝gitbook

cnpm install -g gitbook-cli
gitbook -V 
CLI version: 2.3.2
Installing GitBook 3.2.3
gitbook@3.2.3 ..\AppData\Local\Temp\tmp-20544doJtj1hfVp40\node_modules\gitbook
├── escape-string-regexp@1.0.5
├── escape-html@1.0.3
 。。。。
GitBook version: 3.2.3

3. gitbook使用

3.1 生成目錄和圖書結構

mkdir docker-start
gitbook init
warn: no summary file in this book
info: create README.md
info: create SUMMARY.md
info: initialization is finished

編輯SUMMARY.md,輸入:

* [簡介](README.md)
* [1.Docker入門](chapter1/README.md)
 - [1.1 什么是Docker](chapter1/section1.md)
 - [1.2 Docker基本概念](chapter1/section2.md)
 - [1.3 安裝Docker](chapter1/section3.md)
 - [1.4 使用Docker鏡像](chapter1/section4.md)
 - [1.5 操作容器](chapter1/section5.md)
 - [1.6 訪問倉庫](chapter1/section6.md)
 - [1.6 數據管理](chapter1/section7.md)
* [2.使用Docker部署web應用](chapter2/README.md)
 - [2.1 編寫DockerFile](chapter2/section1.md)
 - [2.2 編寫web應用](chapter2/section2.md)
 - [2.3 構建鏡像](chapter2/section3.md)
 - [2.4 運行web應用](chapter2/section4.md)
 - [2.5 分享鏡像](chapter2/section5.md)
* [結束](end/README.md)

再次執行:

gitbook init
info: create chapter1/README.md
info: create chapter1/section1.md
info: create chapter1/section2.md
info: create chapter1/section3.md
info: create chapter1/section4.md
info: create chapter1/section5.md
info: create chapter1/section6.md
info: create chapter1/section7.md
info: create chapter2/README.md
info: create chapter2/section1.md
info: create chapter2/section2.md
info: create chapter2/section3.md
info: create chapter2/section4.md
info: create chapter2/section5.md
info: create end/README.md
info: create SUMMARY.md
info: initialization is finished

3.2 生成圖書

使用:

gitbook serve .
Live reload server started on port: 35729
Press CTRL+C to quit ...

info: 7 plugins are installed
info: loading plugin "livereload"... OK
info: loading plugin "highlight"... OK
info: loading plugin "search"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 16 pages
info: found 15 asset files
info: >> generation finished with success in 4.0s !

Starting server ...
Serving book on http://localhost:4000

訪問 http://localhost:4000 ,就可以看到圖書了

enter description here

編輯生成的md,gitbook會自動Restart,

enter description here

在當前目錄下,會生成一個_book目錄 ,里面是生成的靜態html,可以發布到服務器直接使用。

4. 使用docker發布gitbook書籍

首先 將_book目錄里的內容拷貝到一個新目錄。

然后編寫Dockerfile

FROM nginx
WORKDIR /usr/share/nginx/html
ADD . /usr/share/nginx/html
EXPOSE 80

build:

docker build -t docker-start-web .
Sending build context to Docker daemon  4.766MB
Step 1/4 : FROM nginx
 ---> 3f8a4339aadd
Step 2/4 : WORKDIR /usr/share/nginx/html
Removing intermediate container a4232f4b6b62
 ---> 91a66299ecad
Step 3/4 : ADD . /usr/share/nginx/html
 ---> 9a9fef80da3b
Step 4/4 : EXPOSE 80
 ---> Running in 59f2b829aba6
Removing intermediate container 59f2b829aba6
 ---> b92c92688046
Successfully built b92c92688046
Successfully tagged docker-start-web:latest

執行:

docker run -p 4000:80 --name docker-start-web -d docker-start-web
f91cf4446b3746c665476b3dd214446a941d838fa9a3ad47680190bb08c9aa48

訪問服務器ip:4000就可以查看到了。


作者:Jadepeng
出處:jqpeng的技術記事本--http://www.cnblogs.com/xiaoqi
您的支持是對博主最大的鼓勵,感謝您的認真閱讀。
本文版權歸作者所有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM