MkDocs是一个快速、简单、华丽的静态网站生成器,适用于构建项目文档。
文档源文件以Markdown编写,并使用一个YAML文件来进行配置。MkDocs生成完全静态的HTML网站,官方的不太好看,我们一般用mkdocs-material这个:
下载地址:git clone https://github.com/squidfunk/mkdocs-material.git
1.制作docker镜像
在官方dockerfile中添加了以下部分,修改安装源为国内的服务器,并升级pip
#Change mirrors RUN cp /etc/apk/repositories /etc/apk/repositories.bak RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories RUN pip install --upgrade pip
完整的
# Copyright (c) 2016-2022 Martin Donath <[email protected]> # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to # deal in the Software without restriction, including without limitation the # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or # sell copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. FROM python:3.9.2-alpine3.13 #Change mirrors RUN cp /etc/apk/repositories /etc/apk/repositories.bak RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories RUN pip install --upgrade pip # Build-time flags ARG WITH_PLUGINS=true # Environment variables ENV PACKAGES=/usr/local/lib/python3.9/site-packages ENV PYTHONDONTWRITEBYTECODE=1 # Set build directory WORKDIR /tmp # Copy files necessary for build COPY material material COPY MANIFEST.in MANIFEST.in COPY package.json package.json COPY README.md README.md COPY requirements.txt requirements.txt COPY setup.py setup.py # Perform build and cleanup artifacts and caches RUN \ apk upgrade --update-cache -a \ && \ apk add --no-cache \ git \ git-fast-import \ openssh \ && \ apk add --no-cache --virtual .build \ gcc \ musl-dev \ && \ pip install --no-cache-dir . \ && \ if [ "${WITH_PLUGINS}" = "true" ]; then \ pip install --no-cache-dir \ "mkdocs-minify-plugin>=0.3" \ "mkdocs-redirects>=1.0"; \ fi \ && \ apk del .build \ && \ for theme in mkdocs readthedocs; do \ rm -rf ${PACKAGES}/mkdocs/themes/$theme; \ ln -s \ ${PACKAGES}/material \ ${PACKAGES}/mkdocs/themes/$theme; \ done \ && \ rm -rf /tmp/* /root/.cache \ && \ find ${PACKAGES} \ -type f \ -path "*/__pycache__/*" \ -exec rm -f {} \; # Set working directory WORKDIR /docs # Expose MkDocs development server port EXPOSE 8000 # Start development server by default ENTRYPOINT ["mkdocs"] CMD ["serve", "--dev-addr=0.0.0.0:8000"]
2.部署服务
2.1准备yml文件
[root@10-10-20-103 qzing]# cat docker-stack-mkdocs.yml version: '3.7' services: zingnext-srm: image: mymkdocs:1.0.0 ports: - 10001:8000 environment: - TZ=Asia/Shanghai volumes: - /qzing/mkdocs/zingnext-srm:/docs - /etc/localtime:/etc/localtime:ro deploy: restart_policy: condition: on-failure zingnext-wms: image: mymkdocs:1.0.0 ports: - 10002:8000 environment: - TZ=Asia/Shanghai volumes: - /qzing/mkdocs/zingnext-wms:/docs - /etc/localtime:/etc/localtime:ro deploy: restart_policy: condition: on-failure zingnext-mes: image: mymkdocs:1.0.0 ports: - 10003:8000 environment: - TZ=Asia/Shanghai volumes: - /qzing/mkdocs/zingnext-mes:/docs - /etc/localtime:/etc/localtime:ro deploy: restart_policy: condition: on-failure zingnext-paas: image: mymkdocs:1.0.0 ports: - 10004:8000 environment: - TZ=Asia/Shanghai volumes: - /qzing/mkdocs/zingnext-paas:/docs - /etc/localtime:/etc/localtime:ro deploy: restart_policy: condition: on-failure nginx-ldap-mkdocs: image: nginx-ldap:1.21.1 ports: - 9001:9001 - 9002:9002 - 9003:9003 - 9004:9004 environment: - TZ=Asia/Shanghai volumes: - /qzing/application/nginx-1.21.1:/application/nginx-1.21.1/ - /etc/localtime:/etc/localtime:ro deploy: restart_policy: condition: on-failure networks: qzing_net: ipam: driver: default
启动服务:
docker stack deploy -c /qzing/docker-stack-mkdocs.yml mkdocs
查看服务:
#docker stack相关命令简介 docker stack deploy -c /deploy/docker-stack.yml mkdocs >部署新的堆栈或更新现有堆栈 docker service ls >列出堆栈中的服务 docker stack ps srment >列出堆栈中的任务 docker stack rm srment >删除部署的stack docker stack services srment >列出堆栈中的服务 #重启容器 docker service scale mkdocs_zingnext-paas=0&&docker service scale mkdocs_zingnext-paas=1
docker部署mkdocs