by Falcon of tinylab.org
Tai Xiao Salon Phase II @ 2015/04/26
Preparing Gitbook environment to install Docker
Take Ubuntu as an example
$ 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
Installing the Gitbook Environment
Perfecting the Gitbook environment
Start the Gitbook environment
$ sudo docker images | grep gitbooktobegit3hub/gitbook-server latest d171079650c8$ sudo docker run -i -t tobegit3hub/gitbook-server /bin/bash
Install Fonts and Git
$ apt-get install git$ apt-get install fonts-arphic-gbsn00lp
To write a book based on Gitbook preparation
Markdown
- Currently the most popular content authoring Markup language
- Google Natural design: Highlight the content, discard the complex format!
- Markdown Basic Syntax
- Markdown Editor: Retext
Pandoc
- Free conversion of various formats
- Pandoc Markdown Syntax
Gitbook
- Gitbook get started quickly
- Gitbook Concise Tutorials
Gitbook Core File
Gitbook output format
Static HTML page
gitbook build ./ --output=./_book/
Pdf
Gitbook Online Preview
Starting server ...
Serving book on http://localhost:4000
- Online preview
- Open with Browser:
http://localhost:4000
Miscellaneous
- Json syntax error
- Book.json: Annotations are not supported.
- JSON Online Validation
syntaxerror:.../book.json:unexpected token o
Gitbook Commissioning
Gitbook Plug-in
- Google Analytics
- Disqus:comments
- Exercises
Gitbook Book instances download and compile books
Preview Books Online
Docker side
Host side
- Access in Browser: http://172.17.0.31:4000
Copy a PDF from Docker
Docker side: Confirm PDF Path
$ readlink -f book.pdf/gitbook/understand_linux_process/book.pdf
Host side:docker cp CONTAINER_ID:PATH HOSTPATH
$ sudo docker ps -aCONTAINER ID IMAGE COMMANDcf5925e tobegit3hub/gitbook-server "/bin/bash"$ sudo docker cp cf5925e:/gitbook/understand_linux_process/book.pdf .
Copy from host to Docker
Two steps
- Get container Mount Path
Direct copy via local CP command
$ 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
Direct-mount volume sharing
New Gitbook Environment Backup/export/import container
Save Container As New Image: Commit
$ sudo docker commit cf5925e tinylab/gitbook$ sudo docker images | grep tinylab/gitbooktinylab/gitbook latest 2106b9f7f675
Export Image file: Save/export
$ sudo docker save tinylab/gitbook > gitbook.tar
Import the image file to another host: Load/import
$ sudo docker load < gitbook.tar
Other operations
Delete/Kill container
docker rm [-f] contaier_id
docker kill contaier_id
Stop container
Start container
docker start container_id
Remove Mirror
New Gitbook Dockerfile
# DockerfileFROM ubuntu:14.04MAINTAINER Falcon [email protected]RUN 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"]
New Gitbook Dockerfile (cont.)
# DockerfileFROM ubuntu:14.04MAINTAINER Falcon [email protected]RUN 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"]
Building images based on Dockerfile
-c,–cpu-shares=0 CPU shares (relative weight)
–cpuset-cpus= CPUs in which to allow execution (0-3, 0,1)
-m,–memory= Memory Limit
Resources
- Gitbook get started quickly
- Gitbook Concise Tutorials
- How to install NVM and Nodejs under Ubuntu environment
- Fast start using Gitbook in Ubuntu environment
- Detailed basic usage of Docker
- Gitbook to support Chinese search
Docker Quick Start: Write a book with Docker + Gitbook