Docker 快速上手:用 Docker + GitBook 寫書
準備 GitBook 環境
安裝 Docker
-
以Ubuntu為例
$ echo deb http://get.docker.io/ubuntu docker main \ | sudo tee /etc/apt/sources.list.d/docker.list $ sudo apt-key adv --keyserver keyserver.ubuntu.com \ --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9 $ sudo apt-get update $ sudo apt-get install -y lxc-docker1234567</div> </td>$ echo deb http : //get.docker.io/ubuntu docker main \| sudo tee / etc / apt / sources . list . d / docker . list$ sudo apt - key adv -- keyserver keyserver . ubuntu . com \-- recv - keys 36A1D7869245C8950F966E92D8576A8BA88D21E9$ sudo apt - get update$ sudo apt - get install - y lxc - docker安裝 GitBook 環境
-
搜索鏡像
$ sudo docker search gitbook NAME DESCRIPTION STARS OFFICIAL AUTOMATED tobegit3hub/gitbook-server 2 [OK]1234</div> </td>$ sudo docker search gitbookNAME DESCRIPTION STARS OFFICIAL AUTOMATEDtobegit3hub / gitbook - server 2 [ OK ]安裝鏡像
- ubuntu
- npm + nodejs
-
gitbook + calibre(ebook-convert)
$ sudo docker pull tobegit3hub/gitbook-server12</div> </td>$ sudo docker pull tobegit3hub / gitbook - server完善 GitBook 環境
-
啟動 GitBook 環境
$ sudo docker images | grep gitbook tobegit3hub/gitbook-server latest d171079650c8 $ sudo docker run -i -t \ tobegit3hub/gitbook-server /bin/bash12345</div> </td>$ sudo docker images | grep gitbooktobegit3hub / gitbook - server latest d171079650c8$ sudo docker run - i - t \tobegit3hub / gitbook - server / bin / bash安裝 字體 和 Git
$ apt-get install git $ apt-get install fonts-arphic-gbsn00lp123</div> </td>$ apt - get install git$ apt - get install fonts - arphic - gbsn00lp用 GitBook 寫書
基礎準備
-
Markdown
- 當前最流行的內容創作標記語言
- Google自然設計:突出內容,拋棄繁雜的格式!
- Markdown 基本語法
- Markdown 編輯器:retext </ul> </li>
-
Pandoc
- 各種格式自由轉換
- Pandoc Markdown 語法 </ul> </li>
-
GitBook
- GitBook 快速上手
- GitBook 簡明教程 </ul> </li> </ul>
-
GitBook 本身是一個 Git 倉庫
- .gitignore: 需要忽略的臨時內容 </ul> </li>
-
重要組件
- README.md: 書籍簡介
- SUMMARY.md: 圖書結構,文章索引
- LANGS.md: 多國語言,每種一個目錄
- GLOSSARY.md: 詞匯表
- cover.jpg: 圖書封面
- cover_small.jpg: 小尺寸圖書封面 </ul> </li> </ul>
-
靜態 HTML 頁面
- gitbook build ./ --output=./_book/ </ul> </li>
-
PDF
- gitbook pdf </ul> </li> </ul>
- 啟動服務
- gitbook serve ./ </ul> </li> </ul>
- 在線預覽
- 用瀏覽器打開:http://localhost:4000 </ul> </li> </ul>
- Json 語法錯誤
- book.json:不支持注釋等。
- JSON 在線驗證 </ul> </li> </ul>
-
GitBook 調試
- export DEBUG=true </ul> </li>
-
GitBook 插件
- Google Analytics
- Disqus: Comments
- Exercises </ul> </li> </ul>
-
下載
$ git clone \ https://github.com/tobegit3hub/understand_linux_process.git123</div> </td>$ git clone \https : //github.com/tobegit3hub/understand_linux_process.git編譯
$ cd understand_linux_process $ gitbook build $ gitbook pdf1234</div> </td>$ cd understand_linux _process$ gitbook build$ gitbook pdf在線預覽圖書
-
Docker 側
-
啟動圖書服務器
$ ifconfig eth0 | grep "inet addr" inet addr:172.17.0.31 ... $ gitbook serve ./ Starting server ... Serving book on http://localhost:4000123456</div> </td>$ ifconfig eth0 | grep "inet addr"inet addr : 172.17.0.31 . . .$ gitbook serve . /Starting server . . .Serving book on http : //localhost:4000主機側
- 在瀏覽器訪問:http://172.17.0.31:4000 </ul> </li> </ul>
-
Docker 側:確認 pdf 路徑
$ readlink -f book.pdf /gitbook/understand_linux_process/book.pdf123</div> </td>$ readlink - f book . pdf/ gitbook / understand_linux_process / book . pdf主機側:docker cp CONTAINER_ID:PATH HOSTPATH
$ sudo docker ps -a CONTAINER ID IMAGE COMMAND cf5925e tobegit3hub/gitbook-server "/bin/bash" $ sudo docker cp \ cf5925e:/gitbook/understand_linux_process/book.pdf .123456</div> </td>$ sudo docker ps - aCONTAINER ID IMAGE COMMANDcf5925e tobegit3hub / gitbook - server "/bin/bash"$ sudo docker cp \cf5925e : / gitbook / understand_linux_process / book . pdf .從 主機 拷入 Docker
-
兩個步驟
- 獲取容器掛載路徑
-
通過本地 cp 命令直接拷貝進去
$ fullid=`sudo docker inspect -f '{{.Id}}' cf5925e` $ gitbook=/var/lib/docker/aufs/mnt/$fullid/gitbook/ $ ls $gitbook understand_linux_process $ cp book.pdf $gitbook/book-from-host.pdf123456</div> </td>$ fullid = ` sudo docker inspect - f '{{.Id}}' cf5925e `$ gitbook = / var / lib / docker / aufs / mnt / $ fullid / gitbook /$ ls $ gitbookunderstand_linux _process$ cp book . pdf $ gitbook / book - from - host . pdf直接掛載卷共享
-
掛載主機 GitBook 目錄到 Docker
$ sudo docker run -i -t \ -v /path/to/mybook/:/gitbook/ \ tinylab/gitbook /bin/bash1234</div> </td>$ sudo docker run - i - t \- v / path / to / mybook / : / gitbook / \tinylab / gitbook / bin / bash新建 GitBook 環境
備份/導出/導入容器
-
保存容器為新鏡像: commit
$ sudo docker commit cf5925e tinylab/gitbook $ sudo docker images | grep tinylab/gitbook tinylab/gitbook latest 2106b9f7f6751234</div> </td>$ sudo docker commit cf5925e tinylab / gitbook$ sudo docker images | grep tinylab / gitbooktinylab / gitbook latest 2106b9f7f675導出鏡像文件: save/export
$ sudo docker save tinylab/gitbook > gitbook.tar12</div> </td>$ sudo docker save tinylab / gitbook > gitbook . tar導入鏡像文件到其他主機上: load/import
$ sudo docker load < gitbook.tar12</div> </td>$ sudo docker load < gitbook . tar其他操作
-
刪除/殺掉容器
- docker rm [-f] contaier_id
- docker kill contaier_id </ul> </li>
-
停止容器
- docker stop container_id </ul> </li>
-
啟動容器
- docker start container_id </ul> </li>
-
刪除鏡像
- docker rmi image_id </ul> </li> </ul>
-
快速構建
$ sudo docker build -t tinylab/gitbook ./12</div> </td>$ sudo docker build - t tinylab / gitbook . /更多參數: Cgroup
</li> </ul>-c, –cpu-shares=0 CPU shares (relative weight)
–cpuset-cpus= CPUs in which to allow execution (0-3, 0,1)
-m, –memory= Memory limit
</blockquote>參考資料
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!相關經驗
相關資訊
sesese色
新建 GitBook Dockerfile
# Dockerfile FROM ubuntu:14.04 MAINTAINER Falcon wuzhangjin@gmail.com RUN sed -i -e "s/archive.ubuntu.com/mirrors.163.com/g" \ /etc/apt/sources.list RUN apt-get -y update RUN apt-get install -y nodejs npm git && \ npm install gitbook -g RUN apt-get install -y calibre RUN apt-get install -y fonts-arphic-gbsn00lp RUN mkdir /gitbook WORKDIR /gitbook EXPOSE 4000 CMD ["gitbook", "serve", "/gitbook"]123456789101112131415</div> </td># DockerfileFROM ubuntu : 14.04MAINTAINER Falcon wuzhangjin @ gmail . comRUN sed - i - e "s/archive.ubuntu.com/mirrors.163.com/g" \/ etc / apt / sources . listRUN apt - get - y updateRUN apt - get install - y nodejs npm git && \npm install gitbook - gRUN apt - get install - y calibreRUN apt - get install - y fonts - arphic - gbsn00lpRUN mkdir / gitbookWORKDIR / gitbookEXPOSE 4000CMD [ "gitbook" , "serve" , "/gitbook" ]新建 GitBook Dockerfile(續)
# Dockerfile FROM ubuntu:14.04 MAINTAINER Falcon wuzhangjin@gmail.com RUN sed -i -e "s/archive.ubuntu.com/mirrors.163.com/g" \ /etc/apt/sources.list RUN apt-get -y update RUN apt-get install -y curl git && cd / && \ git clone https://github.com/creationix/nvm.git nvm && \ echo ". /nvm/nvm.sh" > ~/.bashrc && . ~/.bashrc && \ nvm install 0.12.2 && nvm use 0.12.2 && \ npm install gitbook -g RUN apt-get install -y calibre RUN apt-get install -y fonts-arphic-gbsn00lp RUN mkdir /gitbook WORKDIR /gitbook EXPOSE 4000 CMD ["gitbook", "serve", "/gitbook"]123456789101112131415161718</div> </td># DockerfileFROM ubuntu : 14.04MAINTAINER Falcon wuzhangjin @ gmail . comRUN sed - i - e "s/archive.ubuntu.com/mirrors.163.com/g" \/ etc / apt / sources . listRUN apt - get - y updateRUN apt - get install - y curl git && cd / && \git clone https : //github.com/creationix/nvm.git nvm && \echo ". /nvm/nvm.sh" > ~ / . bashrc && . ~ / . bashrc && \nvm install 0.12.2 && nvm use 0.12.2 && \npm install gitbook - gRUN apt - get install - y calibreRUN apt - get install - y fonts - arphic - gbsn00lpRUN mkdir / gitbookWORKDIR / gitbookEXPOSE 4000CMD [ "gitbook" , "serve" , "/gitbook" ]基于 Dockerfile 構建映像
-
-
從 Docker 拷貝出 pdf
-
GitBook 圖書實例
下載和編譯圖書
SyntaxError:…/book.json:Unexpected token o
</blockquote>
雜項
Starting server …
Serving book on http://localhost:4000
</blockquote>
GitBook 在線預覽
GitBook 輸出格式
GitBook 核心文件
-
-