By Falcon of TinyLab.org
泰晓沙龙第二期 @ 2015/04/26
以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-docker
搜索镜像
$ sudo docker search gitbook
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
tobegit3hub/gitbook-server 2 [OK]
安装镜像
gitbook + calibre(ebook-convert)
$ sudo docker pull tobegit3hub/gitbook-server
启动 GitBook 环境
$ sudo docker images | grep gitbook
tobegit3hub/gitbook-server latest d171079650c8
$ sudo docker run -i -t tobegit3hub/gitbook-server /bin/bash
安装 字体 和 Git
$ apt-get install git
$ apt-get install fonts-arphic-gbsn00lp
Markdown
Pandoc
GitBook
GitBook 本身是一个 Git 仓库
重要组件
静态 HTML 页面
gitbook build ./ --output=./_book/
gitbook pdf
gitbook serve ./
Starting server …
Serving book on http://localhost:4000
http://localhost:4000
SyntaxError:…/book.json:Unexpected token o
GitBook 调试
export DEBUG=true
GitBook 插件
下载
$ git clone https://github.com/tobegit3hub/understand_linux_process.git
编译
$ 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:4000
主机侧
Docker 侧:确认 pdf 路径
$ 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 .
两个步骤
通过本地 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.pdf
挂载主机 GitBook 目录到 Docker
$ sudo docker run -i -t -v /path/to/mybook/:/gitbook/ tinylab/gitbook /bin/bash
保存容器为新镜像: commit
$ sudo docker commit cf5925e tinylab/gitbook
$ sudo docker images | grep tinylab/gitbook
tinylab/gitbook latest 2106b9f7f675
导出镜像文件: save/export
$ sudo docker save tinylab/gitbook > gitbook.tar
导入镜像文件到其他主机上: load/import
$ sudo docker load < gitbook.tar
删除/杀掉容器
docker rm [-f] contaier_id
docker kill contaier_id
停止容器
docker stop container_id
启动容器
docker start container_id
删除镜像
docker rmi image_id
# 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"]
# 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"]
快速构建
$ sudo docker build -t tinylab/gitbook ./
更多参数: 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
Docker 快速上手:用 Docker + GitBook 写书
原文地址:http://blog.csdn.net/tinylab/article/details/45330881