Public Repository

Last pushed: 8 months ago
Short Description
H2 database docker container with Web UI
Full Description

h2db

H2 database docker container with Web UI.

Usage

You should put the database files on a volume on you host system or in a container based data volume.
The following shows how to run the H2 database on files to be persisted in host computers file system.

Annoying thing is that the windows filesystem may not get mounted as a volume when the virtual machine is used (as it is often when you use Docker Toolbox). As a workaround: mount a directory from user directory or add the directory you want to use as a volume to your virtual machine (like the user directory by default is).

Run docker container:

docker run -d -p 1521:1521 -p 81:81 -v /c/Users/joedo/dockermount:/data --name=h2db joedoe/h2db

  • port 1521: TCP/IP port the database may get accessed from, to be used in JDBC connection string
  • port 81: web port for the H2 web based user interface
  • volume v: mapping a shared host file system directory to be accessible from container, in this case the dircetory /c/Users/joedo/dockermount from the Windows host system is mounted to directory /data inside the container

Accessing With Web UI

Point your browser to http://192.168.99.100:81 (with 192.168.99.100 being the IP of your local docker machine, maybe needs to be adjusted to you local settings)

Open and thereby create an empty database by using the following JDB URL: jdbc:h2:/data/h2db/testdb

  • username and password will be sa (= system administrator) by default
  • observe the filename to persist the database to is part of the URL and accessible in file system: /data/h2db/testdb

Accessing With JDBC

Use the following JDBC URL to access a database (@docker.hostname@ to be replaced by your local docker machine IP, e.g. 192.168.99.100):

jdbc:h2:tcp://@docker.hostname@:1521/data/h2db/testd

Docker Pull Command
Owner
joedoe