Docker-JSPWiki
Back to current versionRestore this version

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 :

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, see : to come

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/" harry:jspwiki-2.10.2-svn-14

This means :

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 see a process running on your host container:

[root@vbox dockerfiles]# ps -ef|grep tomcat
centos   11909  1070  5 19:12 ?        00:00:38 java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/tomcat/endorsed -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start

You should also see a running docker container now :

[root@vbox dockerfiles]# docker ps
CONTAINER ID        IMAGE                         COMMAND                CREATED             STATUS              PORTS                  NAMES
e1da0696c689        harry:jspwiki-2.10.2-svn-14   "/bin/sh -c '/usr/lo   13 minutes ago      Up 13 minutes       0.0.0.0:80->8080/tcp   jspwiki_80          

You can also "log in" to your container with the docker exec command and look what is in /var/jspwiki :

[root@vbox dockerfiles]# docker exec -ti jspwiki_80 bash

[tomcat@e1da0696c689 /]$ find /var/jspwiki | head -5
/var/jspwiki
/var/jspwiki/pages
/var/jspwiki/pages/LoginHelp.txt
/var/jspwiki/pages/CopyrightNotice.txt
/var/jspwiki/pages/LeftMenu.txt
[tomcat@e1da0696c689 /]$ exit
exit
[root@vbox dockerfiles]# 

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):

[root@vbox ~]# docker ps 
CONTAINER ID        IMAGE                         COMMAND                CREATED             STATUS              PORTS                  NAMES
e1da0696c689        harry:jspwiki-2.10.2-svn-14   "/bin/sh -c '/usr/lo   42 hours ago        Up 42 hours         0.0.0.0:80->8080/tcp   jspwiki_80          
[root@vbox ~]# docker stop jspwiki_80
jspwiki_80
[root@vbox ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@vbox ~]# 

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):

[root@vbox ~]# docker ps -a
CONTAINER ID        IMAGE                         COMMAND                CREATED             STATUS                            PORTS               NAMES
e1da0696c689        harry:jspwiki-2.10.2-svn-14   "/bin/sh -c '/usr/lo   42 hours ago        Exited (143) About a minute ago                       jspwiki_80          
[root@vbox ~]# docker start jspwiki_80
jspwiki_80
[root@vbox ~]# docker ps
CONTAINER ID        IMAGE                         COMMAND                CREATED             STATUS              PORTS                  NAMES
e1da0696c689        harry:jspwiki-2.10.2-svn-14   "/bin/sh -c '/usr/lo   42 hours ago        Up 3 seconds        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:

[root@vbox ~]# docker ps
CONTAINER ID        IMAGE                         COMMAND                CREATED             STATUS              PORTS                  NAMES
e1da0696c689        harry:jspwiki-2.10.2-svn-14   "/bin/sh -c '/usr/lo   42 hours ago        Up 11 minutes       0.0.0.0:80->8080/tcp   jspwiki_80          
[root@vbox ~]# docker stop jspwiki_80
jspwiki_80
[root@vbox ~]# docker ps -a
CONTAINER ID        IMAGE                         COMMAND                CREATED             STATUS                       PORTS               NAMES
e1da0696c689        harry:jspwiki-2.10.2-svn-14   "/bin/sh -c '/usr/lo   42 hours ago        Exited (143) 6 seconds ago                       jspwiki_80          
[root@vbox ~]# docker rm jspwiki_80
jspwiki_80
[root@vbox ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@vbox ~]# 

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 :

[root@vbox ~]# docker run -d -p 80:8080 --env="jspwiki.baseURL=http://10.0.0.196/" --volume="/var/jspwiki/a:/var/jspwiki/pages" --name jspwiki-80 harry:jspwiki-2.10.2-svn-14
ecbcdafa32b84c024e6c93c0353cf354daa61616b98fa9cdac67d3f3cdc569fb

This way you will get your pages in a directory on the host OS in /home/testuser/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 :