Install a containerized DB2 database with Docker and do the setup
This article gives the steps to quickly get started with DB2 Community Edition on Mac or Windows based machines. It describes the end to end process and dependencies with illustrations and reference links for faster adoption for someone starting on a DB2 journey. DB2 containers also come in flavours of Linux but are not covered here.
With this, a developer does not need to depend on the typical “30 day trial” database provided by the various database vendors, instead one can easily get IBM DB2 installed on a Mac or Windows OS and get started on IBM DB2.
Click Download Docker Desktop
If on Mac, check if your mac runs on an Intel or Apple chip
Download the appropriate version of Docker based on the above steps.
Double click the Docker.dmg file and copy to Applications folder and follow the steps on https://docs.docker.com/desktop/mac/install/ to complete the Docker Desktop install. Provide the required permissions to execute on the computer when prompted.
Similarly for windows follow the steps on the link https://docs.docker.com/desktop/windows/install/
Installing DB2 from an image
The Db2 Community Edition Docker image has the following, preset limitations:
- Memory limit: 16GB
- Core limit: 4 cores
- Database size: 100GB
Create a new directory in which to store your database data and go into the directory
Pull the Db2 Docker image from Docker Hub
docker pull ibmcom/db2
Create an environment variables file, .env_list for your Db2 Community Edition image:
All settings are same except for IS_OSXFS, that is set to true and false for Mac and Windows respectively.
- LICENSE accepts the terms and conditions of the Db2 software contained in this image
- DB2INSTANCE specifies the Db2 instance name
- DB2INST1_PASSWORD specifies the password of the Db2 instance
- DBNAME creates an initial database with the name provided (leave empty if no database is needed)
- BLU sets BLU Acceleration for the Db2 instance to enabled (true) or disabled (false)
- ENABLE_ORACLE_COMPATIBILITY sets Oracle compatibility on the instance to enabled (true) or disabled (false)
- UPDATEAVAIL can be set to YES if there is an existing instance running a new container with a higher Db2 level.
- TO_CREATE_SAMPLEDB creates a sample (pre-populated) database (true)
- REPODB creates a Data Server Manager repository database (true)
- IS_OSXFS identifies the operating system as macOS (true)
- PERSISTENT_HOME is set to true by default and should only specified as false when running Docker for Windows
- HADR_ENABLED configures Db2 HADR for the instance (true). The following three environment variables depend on HADR_ENABLED being set to true:
- ETCD_ENDPOINT specifies your own provided ETCD key-value store. Enter your endpoints with a comma (and no space) as the delimiter. This environment variable is required if HADR_ENABLED is set to true
- ETCD_USERNAME specifies the username credential for ETCD. If left empty, it will use yourDb2 instance
- ETCD_PASSWORD specifies the password credential for ETCD. If left empty, it will use yourDb2 instance password
For Mac save the file by pressing ESCAPE (ESC), and entering:
Similarly for Windows save the file using the file menu.
Enter and run the following command to enter the Docker container:
docker run -h db2server — name db2server — restart=always — detach — privileged=true -p 50000:50000 — env-file .env_list -v /Users/<username>/Docker:/database ibmcom/db2
docker run -h db2server — name db2server — restart=always — detach — privileged=true -p 50000:50000 — env-file env_list.txt -v C:/Users/<user name>/Docker:/database ibmcom/db2
-h assigns the name db2server to the Docker container.
-p specifies the port numbers to use.
--privileged starts the container in privileged mode.
-v defines the volume used for the Db2 Docker image.
docker exec -it db2server /bin/bash
su - db2inst1
Verify that the database specified in the .env_list file is created
db2 list db directory
Download DBeaver for the respective operating system from the link below
Enter the different values as shown and click “Test Connection”
Use DBeaver to create a DB2 schema and tables
Use the db2 instance to connect to the database from the prompt below and run the different commands to setup the database objects
db2 connect to db2db (for mac)
db2 connect to imsdb (for windows)
Congratulations, you are all set for your containerized DB2 journey on Mac or Windows platforms!