!!! 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.
[{TableOfContents }]
!!! 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|http://docs.docker.com/installation/] on the docker site.
Then you need the image, well I uploaded it to the [docker hub|https://registry.hub.docker.com/u/metskem/jspwiki/], 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/" 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 %%small (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. %%small (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 (with also a limit on memory usage added) :
{{{
root@vbox ~]# 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} harry:jspwiki-2.10.2-svn-14; done
7959dbb56983237629a5420437e504a9ce701e4c65d6f54c75d7bb28c7493114
71003b5c8ad429e425dbeb592766e0f7dd584c95c54a46f00a0fd387a1363cd8
dac69d109b21ad6bace992771df45ca73a740e84c7bd4a83d1066f0d099c171c
e718ed81edf56555a3d228ed8c9f449b217e45cdebbc510900e593c6e3fa2ab0
d92af7f908def24138e62f053d8bbe09fc234010dda80085113502efe242332f
[root@vbox ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d92af7f908de harry: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
e718ed81edf5 harry:jspwiki-2.10.2-svn-14 "/bin/sh -c '/usr/lo 5 seconds ago Up 4 seconds 0.0.0.0:9083->8080/tcp jspwiki-9083
dac69d109b21 harry:jspwiki-2.10.2-svn-14 "/bin/sh -c '/usr/lo 6 seconds ago Up 5 seconds 0.0.0.0:9082->8080/tcp jspwiki-9082
71003b5c8ad4 harry:jspwiki-2.10.2-svn-14 "/bin/sh -c '/usr/lo 8 seconds ago Up 7 seconds 0.0.0.0:9081->8080/tcp jspwiki-9081
7959dbb56983 harry:jspwiki-2.10.2-svn-14 "/bin/sh -c '/usr/lo 9 seconds ago Up 8 seconds 0.0.0.0:9080->8080/tcp jspwiki-9080
}}}
And you can get easily rid of them too :
{{{[root@vbox ~]# docker stop `docker ps -aq`
6a4de1df7325
643b7c315123
0ccb68891f02
05a4e4f8db07
6d9b6149cd18
[root@vbox ~]# docker rm `docker ps -aq`
6a4de1df7325
643b7c315123
0ccb68891f02
05a4e4f8db07
6d9b6149cd18
[root@vbox ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@vbox ~]#
}}}