diff --git a/Dockerfile b/Dockerfile index 97ac265..41ae876 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ FROM ubuntu:16.04 MAINTAINER Miroslav Prasil # Set the version you want of Twiki -ARG DOKUWIKI_VERSION=2017-02-19e +ENV DOKUWIKI_VERSION=2017-02-19e ARG DOKUWIKI_CSUM=09bf175f28d6e7ff2c2e3be60be8c65f # Update & install packages & cleanup afterwards @@ -33,8 +33,7 @@ RUN DEBIAN_FRONTEND=noninteractive \ RUN wget -q -O /dokuwiki.tgz "http://download.dokuwiki.org/src/dokuwiki/dokuwiki-$DOKUWIKI_VERSION.tgz" && \ if [ "$DOKUWIKI_CSUM" != "$(md5sum /dokuwiki.tgz | awk '{print($1)}')" ];then echo "Wrong md5sum of downloaded file!"; exit 1; fi && \ mkdir /dokuwiki && \ - tar -zxf dokuwiki.tgz -C /dokuwiki --strip-components 1 && \ - rm dokuwiki.tgz + tar -zxf dokuwiki.tgz -C /dokuwiki --strip-components 1 # Set up ownership RUN chown -R www-data:www-data /dokuwiki @@ -44,8 +43,11 @@ ADD dokuwiki.conf /etc/lighttpd/conf-available/20-dokuwiki.conf RUN lighty-enable-mod dokuwiki fastcgi accesslog RUN mkdir /var/run/lighttpd && chown www-data.www-data /var/run/lighttpd +COPY docker-startup.sh /startup.sh + EXPOSE 80 VOLUME ["/dokuwiki/data/","/dokuwiki/lib/plugins/","/dokuwiki/conf/","/dokuwiki/lib/tpl/","/var/log/"] -ENTRYPOINT ["/usr/sbin/lighttpd", "-D", "-f", "/etc/lighttpd/lighttpd.conf"] +ENTRYPOINT ["/startup.sh"] +CMD ["run"] diff --git a/README.md b/README.md index 3725cf8..f8845f1 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,17 @@ You can now visit the install page to configure your new DokuWiki wiki. For example, if you are running container locally, you can acces the page in browser by going to http://127.0.0.1/install.php +### Run with bind mounts ### + +The run command above will store your data in internal Docker volumes. If you prefer to bind mount directories on your file system, then you can use the `-v` parameter, for example: + + docker run -d -p 80:80 --name my_wiki \ + -v /data/docker/dokuwiki/data:/dokuwiki/data \ + -v /data/docker/dokuwiki/conf:/dokuwiki/conf \ + -v /data/docker/dokuwiki/lib/plugins:/dokuwiki/lib/plugins \ + -v /data/docker/dokuwiki/lib/tpl:/dokuwiki/lib/tpl \ + -v /data/docker/dokuwiki/logs:/var/log + ### Run a specific version ### When running the container you can specify version to download from docker registry by using couple provided tags like *stable* which contains current stable release (this is generaly the same as *latest*) or *oldstable*. You can also use specific version like *2016-06-26a*. @@ -20,6 +31,8 @@ When running the container you can specify version to download from docker regis To upate the image: ------------------- +### With internal volumes ### + First stop your container docker stop my_wiki @@ -42,6 +55,20 @@ afterwards you can remove data container if you want (or keep it for next update, takes no space anyway..) +### With bind mounts ### + +Just stop the old container and run the new one with the same `-v` mapping. Since the data is on your file system, you do not need to do anything special to preserve it between containers. + +#### Handling changes in bundled files inside volumes #### + +If you mount a volume that has previously been used with a newer version of DokuWiki than that installed in the current contaier, the newer files will _not_ be overwritten by those bundled with the current (older) version of DokuWiki. If you want to force a downgrade (at your own risk!), run the container with the `downgrade` command: + + docker run ... mprasil/dokuwiki donwgrade + +Additionally, if you make any changes to the files bundled with DokuWiki that are located in your volumes, these can be restored to the original version using the `overwrite` command: + + docker run ... mprasil/dokuwiki overwrite + Optimizing your wiki -------------------- @@ -54,4 +81,5 @@ Set to proprietary lighttpd header (for lighttpd < 1.5) Build your own -------------- - docker build -t my_dokuwiki . \ No newline at end of file + docker build -t my_dokuwiki . + diff --git a/docker-startup.sh b/docker-startup.sh new file mode 100755 index 0000000..0b5a863 --- /dev/null +++ b/docker-startup.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +set -eu +set -o pipefail + +# Updating DokuWiki may need to change files in directories which we hold in +# volumes, e.g. `data` or `conf`. Therefore, we need to make sure these files +# are there when the container is started, not only when it is created. We do +# this by keeping track which version we last installed and update as necessary, +# or fully populate these folders if this is the first run. + +dokudir=/dokuwiki +tmpdir=/tmp/dokuwiki +verfile=.last-version +containerver="$(date -f <(echo "$DOKUWIKI_VERSION" | tr -d '[:alpha:]') +%s)" + +if [ ! -d "$dokudir" ]; then + echo "DokuWiki does not appear to be installed correctly at: $dokudir." >&2 + exit 1 +fi + +# Check for downgrade/overwrite parameters +if [ "$1" = 'downgrade' ]; then downgrade=1; else downgrade=0; fi +if [ "$1" = 'overwrite' ]; then overwrite=1; else overwrite=0; fi + +if [ "$1" = 'run' ] || [ "$1" = 'downgrade' ] || [ "$1" = 'overwrite' ]; then + # Check each volume directory in turn + for d in conf data lib/plugins lib/tpl; do + if [ -f "$dokudir/$d/$verfile" ]; then + volumever="$(date -f <(awk '{print $1}' "$dokudir/$d/$verfile" | tr -d '[:alpha:]') +%s)" + else + volumever=0 + fi + + if [ "$volumever" -eq "$containerver" ] && [ ! "$overwrite" -eq 1 ]; then + # Do nothing for equal versions + continue + elif [ "$volumever" -lt "$containerver" ] || [ "$downgrade" -eq 1 ] || [ "$overwrite" -eq 1 ]; then + # First, unpack a temporary copy of the current DokuWiki version + if [ ! -d "$tmpdir" ]; then + mkdir "$tmpdir" + tar -zxf /dokuwiki.tgz -C "$tmpdir" --strip-components 1 + fi + + # Then, update if the container version is newer than the volume version + # Or if overridden using `downgrade` + echo "Migrating $d..." + cp -r "$tmpdir/$d/"* "$dokudir/$d/" + cp "$tmpdir/VERSION" "$dokudir/$d/$verfile" + elif [ "$volumever" -gt "$containerver" ]; then + # Otherwise print an error message and stop + cat >&2 <