$ docker run -it -d --name gitbook -p 8895:8001 -v /data/wangjl/test/GitBook:/home/tom/GitBook node:13.12.0 bash
Change the uid of user tom in the containner to your id on the host as shown above.
# usermod -u 1001 tom
下载镜像
$ docker pull node:13.12.0
启动容器
$ docker run -it -d --name gitbook -p 8895:8001 -v /data/wangjl/test/GitBook:/home/tom/GitBook node:13.12.0 bash
进入容器
$ docker exec -it gitbook bash
root@628ad6f6f632:/# node --version
v13.12.0
root@628ad6f6f632:/# npm --version
6.14.4
安装app
# npm install gitbook-cli -g
查看app版本号
# gitbook --version
CLI version: 2.3.2
Installing GitBook 3.2.3
GitBook version: 3.2.3
构建书
# cd /home/tom/GitBook/
初始化
# gitbook init
info: create SUMMARY.md
info: initialization is finished
编辑书
# cat >> README.md
this is a test
# header1
## header2
var a=3;
^C
构建
# gitbook build
gitbook build [当前路径] [输出路径]
gitbook build ./ doc # 默认打包输出到当前路径下面的 doc 文件夹中
可用从浏览器预览了,通过宿主机开启的http服务。
gitbook serve 默认使用 4000 端口访问。
(2) 添加用户
$ id #宿主机查询自己的uid
uid=1001(wangjl) gid=1001(wangjl) groups=1001(wangjl),1004(docker)
容器内添加相同uid的用户:
# useradd -s /bin/bash -d /home/tom -m tom -u 1001
# passwd tom
# chown -R tom:tom /home/tom
# su tom
$ cd ~/GitBook #now /home/tom/GitBook
此时,可以在宿主机编辑 md 文件了。
(3) 提交为新镜像
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2d938d0f926a node:13.12.0 "docker-entrypoint.s." 11 minutes ago Up 11 minutes 0.0.0.0:8895->8001/tcp, :::8895->8001/tcp gitbook
$ docker commit 2d93 dawneve/gitbook:3.2.3
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
dawneve/gitbook 3.2.3 2bd76651845a 7 seconds ago 1.18GB
node 13.12.0 c31fbeb964cc 2 years ago 943MB
billryan/gitbook latest e26d874c0165 4 years ago 1.34GB
发送到远端仓库
$ docker push dawneve/gitbook:3.2.3
检查: https://hub.docker.com/u/dawneve
Content type
Image
Digest
sha256:74c859aeb…
Size
423.7 MB
Last updated
about 4 years ago
docker pull dawneve/gitbook:3.2.3