Db2 version 12.1 is ready for testing |
Db2 Community Edition and Docker/Podman
For the Db2 installation on my laptop I opted for the Db2 Community Edition because it is used (and loved) by many Db2 users for personal education and testing. The edition can be used in non-production environments only, but offers access to most Db2 features. For Db2 version 12.1, instances of the Community Edition are limited to 4 processor cores and a maximum of 8 GB of memory. Db2 uses only those resources even if your machine has more compute power.
In addition to the regular installation method IBM offers a containerized version as Db2 Community Edition for Docker. Even though it says "Docker", it runs in other container environments like Podman. The latter is a rootless platform which makes it more secure to run containers. Its regular command is "podman", but it also provides an alias "docker", so that you can run commands unchanged. If you don't want to use the command line but a UI tool, then consider Podman Desktop.
Containerized Db2 on Linux
For the installation, I roughly followed what is described in the Db2 documentation on installing the Db2 Community Edition Docker image on Linux systems. I started by pulling the image:
docker pull icr.io/db2_community/db2
Next, in my local file system, I have a "db2" directory in which I created a subfolder "Docker" ("cd db2", "mkdir Docker"). That directory "Docker" is used to store configuration and data files for the running container. Thus, the data is still available after deleting the container.
Thereafter, I created a file "db2_env_list" in folder "db2" and added the configuration as documented in step 6. The settings are needed to accept the Db2 license, determine instance name, create a test database, and more. RTFM :).
Last, I ran the following command to kick off the Db2 installation within a new container named "db2server".
docker run -h db2server --name db2server --restart=always --detach --privileged=true -p 50000:50000 --env-file db2_env_list -v ./Docker:/database icr.io/db2_community/db2
Note that used "./Docker:/database" with a dot (.) added as first character when compared to the documented command. I also had to change the file name with the configuration. With the installation progressing, I followed the output and hence the logs:
podman logs -f db2server
Docker/podman logs indicating progress with Db2 installation |
Once the Db2 instance and test database were available, I used the command as shown in the docs to connect to the running container and log into the db2inst1 account.
docker exec -ti db2server bash -c "su - db2inst1"
With that, my Db2 v12.1 was set up and ready for tests.
If you have feedback, suggestions, or questions about this post, please reach out to me on Mastodon (@data_henrik@mastodon.social) or LinkedIn