You can use the Db2® Community Edition to quickly develop, test, and build applications to work with your business’s operational and analytic workloads.
About this task
This procedure installs a Docker image of Db2 11.5.4 Community Edition on Apple macOS systems of version 10.10 or higher, equipped with Hyperkit. Hyperkit is a lightweight macOS virtualization solution built on top of the Hypervisor framework. The procedure assumes that you have Docker installed on a macOS system, using the steps outlined in Install Docker Desktop on Mac. The Db2 Community Edition Docker image has the following, preset limitations:
- Memory limit: 16GB
- Core limit: 4 cores
- Database size: 100GB
Procedure
1.From the command line, create a new directory in which to store your database data:
mkdir Docker
2.Go to this directory by entering the following command:
cd Docker
3.Pull the Db2 Docker image from Docker Hub:
docker pull ibmcom/db2
4.Create an environment variables file, .env_list, for your Db2 Community Edition image:
vi .env_list
5.Paste the following into the environment variables file:
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=true // 非常重要!!!! PERSISTENT_HOME=false HADR_ENABLED=false ETCD_ENDPOINT= ETCD_USERNAME= ETCD_PASSWORD=
- 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 your Db2 instance
- ETCD_PASSWORD specifies the password credential for ETCD. If left empty, it will use your Db2 instance password
6.Save the file by pressing ESCAPE (ESC), and entering:
:wq!
7.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
-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.
8.Enter the following command to access the running Db2 instance within your Docker container:
docker exec -ti db2server bash -c "su – db2inst1"
where db2inst1 is the value associated with the DB2INSTANCE variable in your .env_list file.
9.You can now create a Db2 database within the active instance.