Mkdocs

Based on https://hub.docker.com/r/polinux/mkdocs but using mkdocs-material.

Also used for this documentation.

docker/mkdocs/Dockerfile

FROM alpine:latest

ENV MKDOCS_VERSION=1.0.4 \
    GIT_REPO='false' \
    LIVE_RELOAD_SUPPORT='false' \
    ADD_MODULES='false'

RUN \
    apk add --update \
        ca-certificates \
        bash \
        git \
        openssh \
        python3 \
        python3-dev && \
    pip3 install --upgrade pip && \
    pip install mkdocs==${MKDOCS_VERSION} && \
    rm -rf /tmp/* /var/tmp/* /var/cache/apk/* /var/cache/distfiles/*

COPY ./docker/mkdocs/bootstrap.sh /bootstrap.sh

RUN chmod +x /bootstrap.sh

WORKDIR /docs

ENTRYPOINT ["/bootstrap.sh"]

docker/mkdocs/bootstrap.sh

#!/bin/bash
set -eu
#### "Magic starts Here" - H. Potter #####
### Install themes
if [[ ${ADD_MODULES} != 'false' ]]; then
  echo "Installing additional modules: ${ADD_MODULES}"
  pip install -q ${ADD_MODULES}
fi

check_install_status () {
  if [[ ! -e /docs ]]; then
    echo "No documentation folder available. Creating new one."
    mkdir -p /docs
  fi
  cd /docs
  if [[ ! -e "mkdocs.yml" ]]; then
    echo "No previous config. Starting fresh instalation"
    mkdocs new .
  fi
}
start_mkdocs () {
  if [[ ${LIVE_RELOAD_SUPPORT} != 'true' ]]; then
    echo "[ DISABLED ] - livereload"
    LRS='--no-livereload'
  else
    echo "[ ENABLED ] - livereload"
    LRS=''
  fi
  cd /docs
  echo "Starting MKDocs"
  mkdocs serve -a 0.0.0.0:8000 $LRS
}

get_docs () {
  if [[ ! -e /docs ]]; then
    echo "Downloading documentation from Git Repository"
    git clone ${GIT_REPO} /docs
  fi
}

if [ ${GIT_REPO} != 'false' ]; then
  get_docs
  start_mkdocs
else
  check_install_status
  start_mkdocs
fi

docker-compose.yml

version: '3.7'

services:
  mkdocs:
    build:
        context: '.'
        dockerfile: docker/mkdocs/Dockerfile
    ports: 
      - "${MKDOCS_PORT}:8000"
    volumes: 
      - './src:/docs'    
    environment:
      - ADD_MODULES=mkdocs-material
      - LIVE_RELOAD_SUPPORT=true