Add support for storing data in bind-mounted directories

master
Andrei Poenaru 7 years ago
parent 2b912c904b
commit b7bc34a36c
  1. 8
      Dockerfile
  2. 18
      README.md
  3. 68
      docker-startup.sh

@ -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"]

@ -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,10 @@ 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.
Optimizing your wiki
--------------------
@ -55,3 +72,4 @@ Build your own
--------------
docker build -t my_dokuwiki .

@ -0,0 +1,68 @@
#!/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
verfile=.last-version
if [ ! -d "$dokudir" ]; then
echo "DokuWiki does not appear to be installed correctly at: $dokudir." >&2
exit 1
fi
# Unpack a temporary copy
tmpdir=/tmp/dokuwiki
mkdir "$tmpdir"
tar -zxf /dokuwiki.tgz -C "$tmpdir" --strip-components 1
containerver="$(date -f <(awk '{print $1}' "$tmpdir/VERSION" | tr -d '[:alpha:]') +%s)"
# 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
# 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 ... andreipoe/dokuwiki donwgrade
EOM
exit 2
fi
done
# Ensure persmissions are set correctly
chown -R www-data:www-data "$dokudir"
# Run the web server
/usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf
else
# Handle custom commands otherwise
exec "$@"
fi
Loading…
Cancel
Save