Docker Quick Start: Write a book with Docker + Gitbook

Source: Internet
Author: User
Tags docker ps docker cp

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
    • Search image

      $ sudo docker search gitbookNAME  DESCRIPTION   STARS     OFFICIAL   AUTOMATEDtobegit3hub/gitbook-server 2             [OK]
    • Install image

      • Ubuntu
      • NPM + Nodejs
      • Gitbook + calibre (Ebook-convert)

        $ sudo docker pull tobegit3hub/gitbook-server
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 itself is a Git repository

      • . Gitignore: Temporary content that needs to be ignored
    • Important Components

      • README.MD: A brief introduction to books
      • SUMMARY.MD: Book structure, article index
      • LANGS.MD: Multi-lingual, one directory per type
      • GLOSSARY.MD: Glossary
      • Cover.jpg: Book cover
      • Cover_small.jpg: Small size book cover
Gitbook output format
    • Static HTML page

      • gitbook build ./ --output=./_book/
    • Pdf

      • gitbook pdf
Gitbook Online Preview
    • Start the service
      • gitbook serve ./

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

      • export DEBUG=true
    • Gitbook Plug-in

      • Google Analytics
      • Disqus:comments
      • Exercises
Gitbook Book instances download and compile books
    • Download

      $ git clone https://github.com/tobegit3hub/understand_linux_process.git
    • Compile

      $ cd understand_linux_process$ gitbook build$ gitbook pdf
Preview Books Online
    • Docker side

      • Start the book server

        $ ifconfig eth0 | grep "inet addr"inet addr:172.17.0.31 ...$ gitbook serve ./Starting server ...Serving book on http://localhost:4000
    • 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
    • Mount host Gitbook directory to Docker

      $ sudo docker run -i -t   -v /path/to/mybook/:/gitbook/   tinylab/gitbook /bin/bash
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

      • docker stop container_id
    • Start container

      • docker start container_id
    • Remove Mirror

      • docker rmi image_id
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
    • Build quickly

      $ sudo docker build -t tinylab/gitbook ./
    • More parameters: Cgroup

-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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.