Docker

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 uses the alpine linux parent image.
We install openjdk7-jre and tomcat8 followed by JSPWiki itself (including the default pages).

What are the prereqs to run it ?#

Well, you only need a docker runtime. See the installation instructions on the docker site for details.

Then you need the image, you can download it from the docker hub. Just download it with the docker pull metskem/docker-jspwiki command.

How do I run it#

The most simple way to go is (on your local machine):

docker run -d -p 8080:8080 --name jspwiki metskem/docker-jspwiki

This means :

How can I check it ?#

Just point your browser at the baseURL, that should give you a working wiki right away !

You should also see a running docker container :

metskem@athena:~/workspace/docker-jspwiki$ docker ps
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                    NAMES
5f0f5b0b5996        metskem/docker-jspwiki   "/usr/local/tomcat/bi"   4 minutes ago       Up 4 minutes        0.0.0.0:8080->8080/tcp   stupefied_lamarr

You can also execute commands inside the jspwiki container with the docker exec command and, for example, look at the last 5 lines in /var/jspwiki/logs/jspwiki.log :

metskem@athena:~/workspace/docker-jspwiki$ docker exec -ti stupefied_lamarr tail -5 /var/jspwiki/logs/jspwiki.log
2016-03-28 09:34:35,070 [localhost-startStop-1] INFO org.apache.wiki.util.UtilJ2eeCompat  - apache tomcat detected
2016-03-28 09:34:35,073 [localhost-startStop-1] INFO org.apache.wiki.ajax.WikiAjaxDispatcherServlet  - WikiAjaxDispatcherServlet initialized.
2016-03-28 09:34:35,075 [localhost-startStop-1] INFO org.apache.wiki.WikiServlet  - WikiServlet initialized.
2016-03-28 09:34:38,054 [http-nio-8080-exec-1] INFO org.apache.wiki.util.PropertyReader JSPWiki:/ JSPWiki:http://localhost:8080/ - No jspwiki.custom.config defined for this context, looking for custom properties file with default name of: /jspwiki-custom.properties
2016-03-28 09:34:38,057 [http-nio-8080-exec-1] INFO org.apache.wiki.util.PropertyReader JSPWiki:/ JSPWiki:http://localhost:8080/ - No custom property file found, relying on JSPWiki defaults.

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:~/workspace/docker-jspwiki$ docker ps
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                    NAMES
5f0f5b0b5996        metskem/docker-jspwiki   "/usr/local/tomcat/bi"   6 minutes ago       Up 6 minutes        0.0.0.0:8080->8080/tcp   stupefied_lamarr
metskem@athena:~/workspace/docker-jspwiki$ docker stop stupefied_lamarr 
stupefied_lamarr
metskem@athena:~/workspace/docker-jspwiki$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
metskem@athena:~/workspace/docker-jspwiki$ docker ps -a
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS                       PORTS               NAMES
5f0f5b0b5996        metskem/docker-jspwiki   "/usr/local/tomcat/bi"   6 minutes ago       Exited (143) 4 seconds ago                       stupefied_lamarr
metskem@athena:~/workspace/docker-jspwiki$ 

You can restart it 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:~/workspace/docker-jspwiki$ docker start stupefied_lamarr 
stupefied_lamarr
metskem@athena:~/workspace/docker-jspwiki$ docker ps
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                    NAMES
5f0f5b0b5996        metskem/docker-jspwiki   "/usr/local/tomcat/bi"   7 minutes ago       Up 5 seconds        0.0.0.0:8080->8080/tcp   stupefied_lamarr
metskem@athena:~/workspace/docker-jspwiki$

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, then you can remove it with the docker rm command (or use docker rm -f to forcibly remove it right away):

metskem@athena:~/workspace/docker-jspwiki$ docker ps
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                    NAMES
5f0f5b0b5996        metskem/docker-jspwiki   "/usr/local/tomcat/bi"   9 minutes ago       Up About a minute   0.0.0.0:8080->8080/tcp   stupefied_lamarr
metskem@athena:~/workspace/docker-jspwiki$ docker stop stupefied_lamarr 
stupefied_lamarr
metskem@athena:~/workspace/docker-jspwiki$ docker ps -a
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS                       PORTS               NAMES
5f0f5b0b5996        metskem/docker-jspwiki   "/usr/local/tomcat/bi"   9 minutes ago       Exited (143) 6 seconds ago                       stupefied_lamarr
metskem@athena:~/workspace/docker-jspwiki$ docker rm stupefied_lamarr 
stupefied_lamarr
metskem@athena:~/workspace/docker-jspwiki$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
metskem@athena:~/workspace/docker-jspwiki$

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 8080:8080 --env="jspwiki_baseURL=http://localhost/" --name jspwiki_8080 --volume="/home/metskem/jspwiki-pages:/var/jspwiki/pages"  metskem/docker-jspwiki
240232ebb32e58dee7ad95471128210f71007bbeb11735ffd5394113959ace75

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://localhost:${PORT}/" --name jspwiki-${PORT} metskem/docker-jspwiki; done
68481eed8d609ac91711a78bd80505b398a8a37c9cc435e44eb0b2b7f881444b
b3b967dc4fe721d5efce65959bfd5b4fa6061e053b3fd7b6d814bfc68a0a5261
6a23a3ac3df9aaf1a7f2dda96b6a535d58d06a429f458edaa4101ec89a6416e1
b55b716ed49ff6ca6ba581794fe4ba5bde0439e10301f78acb62d5dec1118304
73d4cd8f29a072884a965ad3a86a5d090762fc046fe424c7b842b1c0b3a72122
metskem@athena:~$ docker ps
CONTAINER ID        IMAGE                           COMMAND                CREATED             STATUS              PORTS                    NAMES
73d4cd8f29a0        metskem/docker-jspwiki   "/bin/sh -c '/usr/lo   4 seconds ago       Up 3 seconds        0.0.0.0:9084->8080/tcp   jspwiki-9084        
b55b716ed49f        metskem/docker-jspwiki   "/bin/sh -c '/usr/lo   4 seconds ago       Up 3 seconds        0.0.0.0:9083->8080/tcp   jspwiki-9083        
6a23a3ac3df9        metskem/docker-jspwiki   "/bin/sh -c '/usr/lo   4 seconds ago       Up 3 seconds        0.0.0.0:9082->8080/tcp   jspwiki-9082        
b3b967dc4fe7        metskem/docker-jspwiki   "/bin/sh -c '/usr/lo   5 seconds ago       Up 4 seconds        0.0.0.0:9081->8080/tcp   jspwiki-9081        
68481eed8d60        metskem/docker-jspwiki   "/bin/sh -c '/usr/lo   5 seconds ago       Up 4 seconds        0.0.0.0:9080->8080/tcp   jspwiki-9080        
      

And you can easily get 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

How to build (and customize) it yourself#

The docker-jspwiki images is an automated build image, which means it is linked to a github repository.