Merged in andrei_poenaru/docker-dokuwiki/bind-mounts (pull request #9)

Add support for storing data in bind-mounted directories

Approved-by: Miroslav Prasil <miroslav@prasil.info>
master
Andrei Poenaru 7 years ago committed by Miroslav Prasil
commit 95bf337a86
  1. 10
      Dockerfile
  2. 28
      README.md
  3. 73
      docker-startup.sh

@ -9,7 +9,7 @@ FROM ubuntu:16.04
MAINTAINER Miroslav Prasil <miroslav@prasil.info> MAINTAINER Miroslav Prasil <miroslav@prasil.info>
# Set the version you want of Twiki # Set the version you want of Twiki
ARG DOKUWIKI_VERSION=2017-02-19e ENV DOKUWIKI_VERSION=2017-02-19e
ARG DOKUWIKI_CSUM=09bf175f28d6e7ff2c2e3be60be8c65f ARG DOKUWIKI_CSUM=09bf175f28d6e7ff2c2e3be60be8c65f
# Update & install packages & cleanup afterwards # 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" && \ 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 && \ if [ "$DOKUWIKI_CSUM" != "$(md5sum /dokuwiki.tgz | awk '{print($1)}')" ];then echo "Wrong md5sum of downloaded file!"; exit 1; fi && \
mkdir /dokuwiki && \ mkdir /dokuwiki && \
tar -zxf dokuwiki.tgz -C /dokuwiki --strip-components 1 && \ tar -zxf dokuwiki.tgz -C /dokuwiki --strip-components 1
rm dokuwiki.tgz
# Set up ownership # Set up ownership
RUN chown -R www-data:www-data /dokuwiki 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 lighty-enable-mod dokuwiki fastcgi accesslog
RUN mkdir /var/run/lighttpd && chown www-data.www-data /var/run/lighttpd RUN mkdir /var/run/lighttpd && chown www-data.www-data /var/run/lighttpd
COPY docker-startup.sh /startup.sh
EXPOSE 80 EXPOSE 80
VOLUME ["/dokuwiki/data/","/dokuwiki/lib/plugins/","/dokuwiki/conf/","/dokuwiki/lib/tpl/","/var/log/"] 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"]

@ -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 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 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 ### ### 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*. 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: To upate the image:
------------------- -------------------
### With internal volumes ###
First stop your container First stop your container
docker stop my_wiki 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..) (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 Optimizing your wiki
-------------------- --------------------
@ -55,3 +82,4 @@ Build your own
-------------- --------------
docker build -t my_dokuwiki . docker build -t my_dokuwiki .

@ -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 <<EOM
This volume has perviously been used with a newer version of DokuWiki.
If you want to force a downgrade (at your own risk!), run the \`downgrade\` command:
docker run ... mprasil/dokuwiki donwgrade
EOM
exit 2
fi
done
# Clean up any temporary files
rm -rf "$tmpdir"
# Ensure persmissions are set correctly
chown -R www-data:www-data "$dokudir"
# Run the web server
exec /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf
else
# Handle custom commands otherwise
exec "$@"
fi
Loading…
Cancel
Save