Running in Docker - wiltondb/wiltondb GitHub Wiki

On this page:

In general, WiltonDB RPM and DEB packages are intended to be used with "full" Linux environment - with a separate postgres user and postgresql service controlled by systemd.

Examples below show how to run WiltonDB inside a Docker container when DB cluster files are placed inside the container itself. Such setup is only intended to be used with temporary DB data for testing purposes. All data will be lost when container is deleted.

To use containerized WiltonDB with persistent DB cluster it is necessary to prepare DB cluster files on a host machine and mount DB cluster directory into a container like this:

docker run ... -v /path/to/existing/db/cluster/on/host:/var/lib/pgsql/

Persistent DB cluster configuration depends on the environment, there is currently no ready-to-use Dockerfile provided for this scenario.

Running WiltonDB in a container

Lets build and run WiltonDB ephemeral container using Ubuntu 24.04 as a host machine:

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 24.04 LTS
Release:	24.04
Codename:	noble

Install Docker:

$ sudo snap install docker
docker 24.0.5 from Canonical✓ installed
$ docker -v
Docker version 24.0.5, build ced0996

Clone the Dockerfile repo and build the image:

$ git clone https://github.com/wiltondb/wdb_docker_ephemeral
$ cd wdb_docker_ephemeral
$ sudo docker build . -t wiltondb1
[...]
=> [4/4] RUN bash /var/lib/pgsql/wiltondb-setup                                              24.1s 
 => exporting to image                                                                         6.1s 
 => => exporting layers                                                                        6.1s 
 => => writing image sha256:8caf15dd135fe96705e9597413c0bcb76c3359e0ecdcd8591e8047d63e62d545   0.0s 
 => => naming to docker.io/library/wiltondb1

Create a container from the newly built image forwarding default ports for both PostgreSQL protocol (port 5432) and TDS (port 1433) protocol connections:

$ sudo docker run -id --name wdb1 -p 5432:5432 -p 1433:1433 wiltondb1
11ff9319e705a848ef3a97495a8ef54c569ec4f3900eab0938d22231b1383853

Check that WiltonDB running in container can be accessed from host with sqlcmd:

$ sqlcmd -S 127.0.0.1,1433 -U wilton -P wilton
1> select @@version
2> go
version
--------------------------------------------------------------------
Babelfish for PostgreSQL with SQL Server Compatibility - 12.0.2000.8

DB cluster files live inside the container in /var/lib/pgsql/data directory, we can login to container to inspect logs and config files:

$ sudo docker exec -it wdb1 bash
bash-5.1$ id
uid=26(postgres) gid=26(postgres) groups=26(postgres)
bash-5.1$ cd                
bash-5.1$ pwd
/var/lib/pgsql
bash-5.1$ ls ./data/log/
postgresql-Thu.log
bash-5.1$ tail ./data/log/postgresql-Thu.log 
2024-05-30 17:40:57.653 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2024-05-30 17:40:57.653 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2024-05-30 17:40:57.736 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2024-05-30 17:40:57.747 UTC [1] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2024-05-30 17:40:57.747 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 1433
2024-05-30 17:40:57.747 UTC [1] LOG:  listening on IPv6 address "::", port 1433
2024-05-30 17:40:57.845 UTC [10] LOG:  database system was shut down at 2024-05-30 17:38:58 UTC
2024-05-30 17:40:57.862 UTC [1] LOG:  database system is ready to accept connections

Running WiltonDB with systemd inside a container

When running on RHEL/Fedora host Podman allows a straightforward way to run systemd inside the container. Based on this example the following steps can be used to run WiltonDB with systemd on Rocky Linux 8 (expected to work the same way with other popular RHEL derivatives).

$ podman pull rockylinux:8
$ podman run -id --name rocky8 -p 1433:1433 -p 5432:5432 -v /path/to/empt/dir/on/host/:/var/lib/pgsql/ rockylinux:8 /lib/systemd/systemd
$ podman exec -it rocky8 bash
# cat /etc/redhat-release
Rocky Linux release 8.8 (Green Obsidian)
# dnf update
# dnf install epel-release
# dnf install 'dnf-command(copr)'
# dnf copr enable wiltondb/wiltondb
# dnf update
# dnf install wiltondb
# wiltondb-setup
WARNING: Note that either your data directory '/var/lib/pgsql/data' or
         the parent directory '/var/lib/pgsql'
         is a direct mountpoint.  This is usually a bad idea and your
         filesystem layout should ideally look like:
         /ROOT_OWNED_MOUNTPOINT/POSTGRES_OWNED_DIRECTORY/DATADIR.
         See the upstream documentation for more info:
         http://www.postgresql.org/docs/15/static/creating-cluster.html
 * Initializing database in '/var/lib/pgsql/data'
 * Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log
 * Initializing WiltonDB
WARNING: DB superuser 'wilton' was created with password 'wilton', please change the password before allowing remote connections.
 * Initialized, use 'systemctl start postgresql' to start the server
# systemctl start postgresql
# su - postgres
$ psql
postgres=# alter user wilton with password 'strong_password_here';
ALTER ROLE
postgres=# alter system set listen_addresses = '*';
postgres=# exit
$ exit
# systemctl restart postgresql

Now WiltonDB is running in container with ports 1433 and 5432 exposed to host machine. Connecting from host with sqlcmd we can check the running version:

sqlcmd -S 127.0.0.1,1433 -U wilton -P foobar
1> select @@version
2> go
version                                                                                                                                                                                                                                                         
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Babelfish for PostgreSQL with SQL Server Compatibility - 12.0.2000.8
Oct 22 2023 17:48:32
Copyright (c) Amazon Web Services
PostgreSQL 15.4 (EL 1:15.4.wiltondb3.3_2-2.el8) on x86_64-redhat-linux-gnu (Babelfish 3.3.0)                                        

(1 row affected)