系统环境
- CentOS 7
- Docker 18.02.0-ce
编写Dockerfile文件
mkdir gitbook
cd gitbook
vi Dockerfile
以下是Dockerfile的内容
# Use an official Node.js runtime as a parent image
FROM node:8.11.1
# Set npm registry to China Taobao and install Gitbook
RUN npm config set registry https://registry.npm.taobao.org && \
npm install gitbook-cli -g && \
gitbook -V && \
mkdir /gitbook
# Make port 4000 available to the world outside this container
EXPOSE 4000
CMD ["sh", "-c", "gitbook install /gitbook; gitbook serve /gitbook"]
生成镜像
# 最后是镜像名和版本,可以根据实际情况更改
sudo docker build -t gitbook:3.2.3 .
运行镜像
# 启动可能会较慢
docker run -d -p 4000:4000 -v /home/test/docker_practice:/gitbook gitbook:3.2.3
推送镜像至私有仓库
# 打标签
docker tag gitbook:3.2.3 harbor.test.com/library/gitbook:3.2.3
# 登录私有仓库
docker login harbor.test.com
# 推送至私有仓库
docker push harbor.test.com/library/gitbook:3.2.3