Skip to content

Commit

Permalink
Add guide on using docker, closes #46
Browse files Browse the repository at this point in the history
  • Loading branch information
timvink committed May 27, 2023
1 parent d703f25 commit 355224f
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
101 changes: 101 additions & 0 deletions docs/howto/docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Use with docker

If you follow the `mkdocs-material` [tutorial on installation with `docker`](https://squidfunk.github.io/mkdocs-material/getting-started/#with-docker), you will run into an error if you try to add this plugin saying:

> × Building wheel for numpy (pyproject.toml) did not run successfully.
The reason is that the `mkdocs-material` docker image uses the `alpine` image. `mkdocs-table-reader-plugin` depends on [`pandas`](https://pandas.pydata.org/), which depends on [`numpy`](https://numpy.org/), which in turn requires C++ to install, which is not part of the `alpine` image.

If you need a very small image, you can [adapt the alpine image to support numpy](https://stackoverflow.com/questions/33421965/installing-numpy-on-docker-alpine), but you are better off using a more complete docker image like `python-slim`. So you need to build a different docker image.

As an example, below is a `Dockerfile` that is adapted from the [mkdocs-material dockerfile](https://github.com/squidfunk/mkdocs-material/blob/master/Dockerfile). You can use it to create a new Docker image that supports `mkdocs-table-reader-plugin`:

```bash
git clone https://github.com/squidfunk/mkdocs-material.git material-git/
cd material-git
# Manually replace `Dockerfile` with the example below
docker build -t YOUR-CONTAINER-NAME .
# Now, inside your own project, you can use:
docker run --rm -it -p 8000:8000 -v ${PWD}:/docs YOUR-CONTAINER-NAME
```

??? info "Dockerfile"

```Dockerfile
FROM python:3-slim

# Build-time flags
ARG WITH_PLUGINS=true

# Environment variables
ENV PACKAGES=/usr/local/lib/python3.11/site-packages
ENV PYTHONDONTWRITEBYTECODE=1

# Set build directory
WORKDIR /tmp

# Copy files necessary for build
COPY material-git/material material
COPY material-git/package.json package.json
COPY material-git/README.md README.md
COPY material-git/requirements.txt requirements.txt
COPY material-git/pyproject.toml pyproject.toml

# Perform build and cleanup artifacts and caches
RUN \
apt update \
&& \
apt install -y \
libcairo2-dev \
libfreetype6-dev \
git \
libturbojpeg-dev \
openssh-server \
zlib1g-dev \
&& \
apt install -y \
gcc \
libffi-dev \
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" \
"pillow>=9.0" \
"cairosvg>=2.5" \
"mkdocs-table-reader-plugin" \
; \
fi \
&& \
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 {} \;

# Trust directory, required for git >= 2.35.2
RUN git config --global --add safe.directory /docs &&\
git config --global --add safe.directory /site

# 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"]
```
"mkdocs-table-rea
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ nav:
- howto/customize_tables.md
- howto/preprocess_tables.md
- howto/project_structure.md
- howto/docker.md
- options.md

theme:
Expand Down

0 comments on commit 355224f

Please sign in to comment.