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, 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 :
- -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)
- harry: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 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
TODO#
- multiple instances
