These instruction uses IMB’s base image and customizes then to have a pre-built image with a database and a user.
Pull a base image
docker pull ibmcom/db2express-c:10.5.0.5-3.10.0
You should now have:
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ibmcom/db2express-c 10.5.0.5-3.10.0 7aa154d9b73c 3 years ago 1.71GB
Create local custom image using Dockerfile.
docker build --tag ibmcom/db2express-c-local .
We need to start database and then tweak its settings.
docker run -d --name db2-build -p 50000:50000 -e 'DB2INST1_PASSWORD=Passw0rd' -e 'LICENSE=accept' ibmcom/db2express-c-local db2start
Now you should have.
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f07afbc6e1c3 ibmcom/db2express-c-local "/entrypoint.sh db2s…" 20 seconds ago Up 19 seconds 22/tcp, 0.0.0.0:50000->50000/tcp db2-build
Connect to a database:
docker exec -it db2-build bash
Create a user.
[root@39674abd09f5 /]# useradd spring
[root@39674abd09f5 /]# echo "spring" | passwd --stdin spring
Changing password for user spring.
Create a database.
[root@f07afbc6e1c3 /]# su - db2inst1
Last login: Mon Nov 26 15:32:34 UTC 2018
[db2inst1@f07afbc6e1c3 ~]$ db2 create database spring
DB20000I The CREATE DATABASE command completed successfully.
[db2inst1@f07afbc6e1c3 ~]$ db2 activate database spring
DB20000I The ACTIVATE DATA
[db2inst1@f07afbc6e1c3 ~]$ db2 connect to spring
Database Connection Information
Database server = DB2/LINUXX8664 10.5.5
SQL authorization ID = DB2INST1
Local database alias = SPRING
[db2inst1@f07afbc6e1c3 ~]$ db2 create bufferpool springpool size 2000 pagesize 16k
DB20000I The SQL command completed successfully.
[db2inst1@f07afbc6e1c3 ~]$ db2 create system temporary tablespace temppace16 pagesize 16k bufferpool springpool
DB20000I The SQL command completed successfully.
[db2inst1@f07afbc6e1c3 ~]$ db2 grant dbadm with dataaccess with accessctrl on database to user spring
DB20000I The SQL command completed successfully.
Stop container
docker stop -t 30 db2-build
Commit it:
docker commit -m "Image with prebuilt spring database" db2-build ibmcom/database-prebuilt:10.5.0.5-3.10.0
Check that it comes up:
docker run --name db2-build-prebuilt -p 50000:50000 ibmcom/database-prebuilt:10.5.0.5-3.10.0
Push to registry:
docker login springsource-docker-private-local.jfrog.io
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ibmcom/database-prebuilt 10.5.0.5-3.10.0 67826abcf7fd About a minute ago 1.89GB
docker tag 67826abcf7fd springsource-docker-private-local.jfrog.io/ibmcom/database-prebuilt:10.5.0.5-3.10.0
docker push springsource-docker-private-local.jfrog.io/ibmcom/database-prebuilt:10.5.0.5-3.10.0