Introduction
IBM Db2 is a robust, enterprise-grade relational database management system known for its high performance, reliability, and scalability. While typically used in enterprise environments, IBM offers a free Community Edition ideal for developers, testers, and learners who want to explore Db2’s capabilities without a full commercial license.
In this guide, we’ll walk through the process of installing the IBM Db2 Community Edition using Docker. This method simplifies the setup by eliminating the need for complex environment configuration and is suitable for both beginners and experienced developers.
You can learn more about Db2 here, and you can also download it from this link.
https://www.ibm.com/db2
Once you've created an account and logged in, you will be able to find the section where you can download the Db2 Community Edition standalone installer for your operating system. This version is separate from the Docker image and is intended for direct installation on Windows or Linux without containerization.
Install docker
In this guide, we’ll walk through the process of installing IBM Db2 Community Edition using Docker. Before we begin, ensure that Docker is installed on your system. If it’s not already set up, take a moment to install it. This tutorial is based on an Ubuntu environment, so the steps provided will reflect that setup.
# Install necessary packages for adding Docker repository and installing Docker
sudo apt install apt-transport-https ca-certificates curl software-properties-common
# Download and add Docker's official GPG key for package verification
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# Add Docker's repository to the system's list of software sources
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
# Update the package index to reflect the addition of the Docker repository
apt-cache policy docker-ce
# Install Docker Community Edition (docker-ce) package
sudo apt install docker-ce
# Check the status of the Docker service to ensure it's running
sudo systemctl status docker
Install Db2
Create an environment variables file, .env_list
, for your Db2 Community Edition image:
vi .env_list
Paste the following into the environment variables file and update the necessary details :
LICENSE=accept
DB2INSTANCE=db2inst1
DB2INST1_PASSWORD=password
DBNAME=testdb
BLU=false
ENABLE_ORACLE_COMPATIBILITY=false
UPDATEAVAIL=NO
TO_CREATE_SAMPLEDB=false
REPODB=false
IS_OSXFS=false
PERSISTENT_HOME=true
HADR_ENABLED=false
ETCD_ENDPOINT=
ETCD_USERNAME=
ETCD_PASSWORD=
Use the command below to install it :
# Run a Docker container with IBM Db2 database
# Replace {container-name} with your desired container name , eg: Db2
# Change the left-side port(50000), which will expose a different port outside the container that can be used to configure it with other applications.
# Don't change the right-side port, as it will always remain the same (50000).
# -p <host_port>:<container_port>
docker run -h db2server \
--name {container-name} \
--restart=always \
--detach \
--privileged=true \
-p 50000:50000 \
--env-file .env_list \
-v /Docker:/database \
icr.io/db2_community/db2
The -v /Docker:/database
flag mounts a local directory (/Docker
) to the container’s /database
path, allowing data persistence outside the container. This ensures your DB2 data remains intact even if the container is stopped or removed.
The image icr.io/db2_community/db2
is pulled from IBM’s container registry, which hosts official DB2 Community Edition images. Using this trusted registry ensures you're getting a secure and up-to-date version of DB2 for your development or testing environment.
Verify that DB2 is installed successfully and check the status of the container.
root@techworldthink1:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6c0d416a2209 icr.io/db2_community/db2 "/var/db2_setup/lib/…" 29 seconds ago Up 29 seconds 22/tcp, 55000/tcp, 60006-60007/tcp, 0.0.0.0:50000->50000/tcp Db2
Start the DB2 services
To start the DB2 services in a Docker container, first, access the container's bash shell using the docker exec
command. You can either open a general bash session or switch to the db2inst1
user shell, which is the default DB2 instance user. Once inside the container, use the db2start
command to start the DB2 services, initializing the DB2 instance and allowing you to perform database operations.
# Open a bash shell in the Db2 container
docker exec -ti Db2 bash
su - db2inst1
# Alternatively, switch to the db2inst1 user shell in the container
docker exec -ti Db2 bash -c "su - db2inst1"
# Start the DB2 services
db2start
Example :
root@techworldthink1:~# docker exec -ti Db2 bash
[root@db2server /]# su - db2inst1
Last login: Sat Apr 12 06:06:57 UTC 2025
[db2inst1@db2server ~]$ db2start
04/12/2025 06:07:06 0 0 SQL1026N The database manager is already active.
SQL1026N The database manager is already active.
Access the DB2 Command line processor (CLP)
Access the Docker container running Db2 as the db2inst1 user
docker exec -ti Db2 bash -c "su - db2inst1"
Once inside the container, execute the db2
command to start the DB2 command-line interface
db2
List all databases in the directory using 'LIST DATABASE DIRECTORY'
LIST DATABASE DIRECTORY
To learn more about CLP commands, check the DB2 documentation. Also, in upcoming blogs, we will cover them in more detail.
To exit the DB2 CLP, use the terminate command
TERMINATE
Example :
root@techworldthink1:~# docker exec -ti Db2 bash -c "su - db2inst1"
Last login: Sat Apr 12 06:17:09 UTC 2025
[db2inst1@db2server ~]$ db2
(c) Copyright IBM Corporation 1993,2007
Command Line Processor for DB2 Client 12.1.1.0
You can issue database manager commands and SQL statements from the command
prompt. For example:
db2 => connect to sample
db2 => bind sample.bnd
For general help, type: ?.
For command help, type: ? command, where command can be
the first few keywords of a database manager command. For example:
? CATALOG DATABASE for help on the CATALOG DATABASE command
? CATALOG for help on all of the CATALOG commands.
To exit db2 interactive mode, type QUIT at the command prompt. Outside
interactive mode, all commands must be prefixed with 'db2'.
To list the current command option settings, type LIST COMMAND OPTIONS.
For more detailed help, refer to the Online Reference Manual.
db2 => LIST DATABASE DIRECTORY
System Database Directory
Number of entries in the directory = 1
Database 1 entry:
Database alias = TESTDB
Database name = TESTDB
Local database directory = /database/data
Database release level = 16.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
db2 => TERMINATE
DB20000I The TERMINATE command completed successfully.
DB2 Client Connection Parameters
These are the key DB2 connection parameters you should be aware of if you want to connect your database to business applications or monitoring tools like DMC.
Host : 9.20.85.104 # Db2 Server IP address or domain name
Port : 50000 # Port number for the DB2 service
Database : {db name} # Name of the database
Username : db2inst1 # DB2 instance username
Password : {db password} # Password for the DB2 instance