Docker for JSPWiki#
After some experiments with Docker I came up with a working solution for running JSPWiki in Tomcat on Linux in a Docker container.
What container is it ?#
The JSPWiki Docker image has 3 level parents :
- centos7 (the base OS we use, pulled from official centos docker hub)
- java7 installed (see dockerfile for details)
- tomcat 8.0.20 installed (see dockerfile for details)
As locally seen with the docker images command :
[root@vbox dockerfiles]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE harry jspwiki-2.10.2-svn-14 3e33f5d2d612 2 minutes ago 618.3 MB harry tomcat-8.0.20 d9e7a3a95230 11 minutes ago 542.7 MB harry java7 c5eb18fad024 7 days ago 501.5 MB centos 7 dade6cb4530a 4 weeks ago 224 MB centos centos7 dade6cb4530a 4 weeks ago 224 MB centos latest dade6cb4530a 4 weeks ago 224 MB
What do I need to run it ?#
Well, the is simple, you "only" need a docker runtime. See the installation instructions
on the docker site.
Then you need the image, well I uploaded it to the docker hub
, you can pull the image with the docker pull metskem/jspwiki:2.10.2-svn-14 command :
metskem@athena:~$ docker pull metskem/jspwiki:2.10.2-svn-14 Pulling repository metskem/jspwiki 3e33f5d2d612: Download complete 511136ea3c5a: Download complete 5b12ef8fd570: Download complete dade6cb4530a: Download complete 359721211f5c: Download complete 98beb40b6504: Download complete fad8a5aad415: Download complete c5eb18fad024: Download complete b454f7f76947: Download complete 4c7411669599: Download complete 4b1b864cc438: Download complete a52662924bc3: Download complete 100d08836b51: Download complete 75249b507083: Download complete 37cdb2454635: Download complete 9813449de08c: Download complete 70ada966eafd: Download complete 5118018723d4: Download complete d9e7a3a95230: Download complete 175239e8dfcf: Download complete b0f0224ac143: Download complete 5052a6834478: Download complete a65f5aa71ffc: Download complete 9a27739e5632: Download complete bd87bfcca5db: Download complete 52261c9107a2: Download complete 8006058ca718: Download complete 436ff3e1b3b8: Download complete b53f530c871d: Download complete fb6a8b342757: Download complete 42a4e3c64949: Download complete c31163905507: Download complete 4e9a2442bed8: Download complete 37df4c62fd11: Download complete ecdbcd1f656f: Download complete 1471a9d1d1ec: Download complete 95ef590ff04d: Download complete Status: Downloaded newer image for metskem/jspwiki:2.10.2-svn-14 metskem@athena:~$ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE metskem/jspwiki 2.10.2-svn-14 3e33f5d2d612 43 hours ago 618.3 MB metskem@athena:~$
How do I run it#
The most simple way to go is :
docker run -d -p 80:8080 --env="jspwiki.baseURL=http://10.0.0.196/" metskem/jspwiki:jspwiki-2.10.2-svn-14
This means :
- -d - detached mode, run the container in the background
- -p 80:8080 - bind the host port (80) to the container port (8080). JSPWiki always runs on port 8080 inside the container.
- --env="jspwiki.baseURL=http://10.0.0.196/" - you have to override this variable, because the jspwiki baseURL must match the URL that you use to access the wiki (the 10.0.0.196 is just an example of course)
- metskem/jspwiki:jspwiki-2.10.2-svn-14 - the name of the image to run
How can I check it ?#
You can point your browser at the baseURL of course, that should give you a working wiki right away !
You should also see a running docker container now :
metskem@athena:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c8c73ddd9876 metskem/jspwiki:2.10.2-svn-14 "/bin/sh -c '/usr/lo 3 minutes ago Up 3 minutes 0.0.0.0:80->8080/tcp focused_goldstine metskem@athena:~$
You can also "log in" to your container with the docker exec command and look what is in /var/jspwiki :
metskem@athena:~$ docker exec -ti c8c73ddd9876 bash [tomcat@c8c73ddd9876 /]$ find /var/jspwiki|head -5 /var/jspwiki /var/jspwiki/pages /var/jspwiki/pages/OLD /var/jspwiki/pages/LoginHelp.txt /var/jspwiki/pages/ApprovalRequiredForUserProfiles.txt [tomcat@c8c73ddd9876 /]$ exit exit metskem@athena:~$
Stopping and starting the container#
To stop the container, simply issue the docker stop command against the containerid (or container name if you gave it a name during first run):
metskem@athena:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e1892e0fe60a metskem/jspwiki:2.10.2-svn-14 "/bin/sh -c '/usr/lo 3 seconds ago Up 2 seconds 0.0.0.0:80->8080/tcp jspwiki_80 metskem@athena:~$ docker stop jspwiki_80 jspwiki_80 metskem@athena:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES metskem@athena:~$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e1892e0fe60a metskem/jspwiki:2.10.2-svn-14 "/bin/sh -c '/usr/lo 46 seconds ago Exited (143) 7 seconds ago jspwiki_80 c8c73ddd9876 metskem/jspwiki:2.10.2-svn-14 "/bin/sh -c '/usr/lo 6 minutes ago Exited (143) About a minute ago focused_goldstine
You can restart it again with the docker start command, you have to find the containerid with the docker ps -a command first , (or simply use the container name if you gave the container a name during first run):
metskem@athena:~$ docker start jspwiki_80 jspwiki_80 metskem@athena:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e1892e0fe60a metskem/jspwiki:2.10.2-svn-14 "/bin/sh -c '/usr/lo 2 minutes ago Up About a minute 0.0.0.0:80->8080/tcp jspwiki_80
As you will notice, after a stop/start you still have the data (pages) that were created after the first container start. (you can check easily with the Recent Changes page)
Removing the container#
If you want to get rid of the container (and all of the data in it !) you first should stop it, and the you can remove it with the docker rm command:
metskem@athena:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e1892e0fe60a metskem/jspwiki:2.10.2-svn-14 "/bin/sh -c '/usr/lo 2 minutes ago Up About a minute 0.0.0.0:80->8080/tcp jspwiki_80 metskem@athena:~$ docker stop jspwiki_80 jspwiki_80 metskem@athena:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES metskem@athena:~$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e1892e0fe60a metskem/jspwiki:2.10.2-svn-14 "/bin/sh -c '/usr/lo 2 minutes ago Exited (143) 6 seconds ago jspwiki_80 c8c73ddd9876 metskem/jspwiki:2.10.2-svn-14 "/bin/sh -c '/usr/lo 8 minutes ago Exited (143) 3 minutes ago focused_goldstine metskem@athena:~$ docker rm jspwiki_80 jspwiki_80 metskem@athena:~$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c8c73ddd9876 metskem/jspwiki:2.10.2-svn-14 "/bin/sh -c '/usr/lo 8 minutes ago Exited (143) 3 minutes ago focused_goldstine
Note that all your data is lost when you remove the container. (You can keep data apart using docker volumes, see next paragraph)
Persistent data#
If you use docker to run jspwiki only for quick test purposes, you probably are not interested in keeping the data (created/changed pages, registered users, logfiles).
But you can also run a jspwiki docker container in production like environments where you want to keep your data even after you removed a container. As an example you might sometimes want to run a newer version of your jspwiki docker container.
To keep data outside of the container, you can use the --volume switch when you fire up the container :
metskem@athena:~$ docker run -d -p 80:8080 --env="jspwiki.baseURL=http://10.0.0.196/" --name jspwiki_80 --volume="/home/metskem/jspwiki-pages:/var/jspwiki/pages" metskem/jspwiki:2.10.2-svn-14 240232ebb32e58dee7ad95471128210f71007bbeb11735ffd5394113959ace75 metskem@athena:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 240232ebb32e metskem/jspwiki:2.10.2-svn-14 "/bin/sh -c '/usr/lo 6 seconds ago Up 6 seconds 0.0.0.0:80->8080/tcp jspwiki_80
This way you will get your pages in a directory on the host OS in /home/metskem/jspwiki-pages.
Obviously, in this case you will not have the initial set of default pages loaded.
Running multiple instances#
You can run multiple instances of the image of course. You only have to make sure they use different TCP ports.
So for example starting 5 containers (with also a limit on memory usage added) :
metskem@athena:~$ for PORT in `seq 9080 9084`; do docker run -d -p ${PORT}:8080 --memory=128m --env="jspwiki.baseURL=http://10.0.0.196:${PORT}/" --name jspwiki-${PORT} metskem/jspwiki:2.10.2-svn-14; done
68481eed8d609ac91711a78bd80505b398a8a37c9cc435e44eb0b2b7f881444b
b3b967dc4fe721d5efce65959bfd5b4fa6061e053b3fd7b6d814bfc68a0a5261
6a23a3ac3df9aaf1a7f2dda96b6a535d58d06a429f458edaa4101ec89a6416e1
b55b716ed49ff6ca6ba581794fe4ba5bde0439e10301f78acb62d5dec1118304
73d4cd8f29a072884a965ad3a86a5d090762fc046fe424c7b842b1c0b3a72122
metskem@athena:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
73d4cd8f29a0 metskem/jspwiki:2.10.2-svn-14 "/bin/sh -c '/usr/lo 4 seconds ago Up 3 seconds 0.0.0.0:9084->8080/tcp jspwiki-9084
b55b716ed49f metskem/jspwiki:2.10.2-svn-14 "/bin/sh -c '/usr/lo 4 seconds ago Up 3 seconds 0.0.0.0:9083->8080/tcp jspwiki-9083
6a23a3ac3df9 metskem/jspwiki:2.10.2-svn-14 "/bin/sh -c '/usr/lo 4 seconds ago Up 3 seconds 0.0.0.0:9082->8080/tcp jspwiki-9082
b3b967dc4fe7 metskem/jspwiki:2.10.2-svn-14 "/bin/sh -c '/usr/lo 5 seconds ago Up 4 seconds 0.0.0.0:9081->8080/tcp jspwiki-9081
68481eed8d60 metskem/jspwiki:2.10.2-svn-14 "/bin/sh -c '/usr/lo 5 seconds ago Up 4 seconds 0.0.0.0:9080->8080/tcp jspwiki-9080
And you can get easily rid of them too :
metskem@athena:~$ docker stop `docker ps -aq` 73d4cd8f29a0 b55b716ed49f 6a23a3ac3df9 b3b967dc4fe7 68481eed8d60 240232ebb32e c8c73ddd9876 metskem@athena:~$ docker rm `docker ps -aq` 73d4cd8f29a0 b55b716ed49f 6a23a3ac3df9 b3b967dc4fe7 68481eed8d60 240232ebb32e c8c73ddd9876 metskem@athena:~$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
