Grabbing a coffee? Install Db2 while you’re away

Installing Db2 on your coffee break

How to install Db2 11.5 on Windows, MacOS or Linux with a single command, in less than 5 minutes

Adam Storm
Jun 27, 2019 · 3 min read

Today IBM released Db2 11.5. While the release is stacked with new functionality, my single favorite feature is the dramatically improved install experience — it’s now possible to install Db2 on Mac, Linux or Windows with a single command, in less than 5 minutes. To put that another way, if you’re about to grab a coffee, start the install now and it’ll be ready by the time you get back.

A short aside — These instructions assume you have Docker installed on your machine. If you haven’t yet installed Docker, you can install it here: Mac, Windows, CentOS, Debian, Fedora, Ubuntu.

This is the single command you’ll need to run to install Db2:

docker run -itd --name db2 --restart unless-stopped -e DBNAME=testdb -v ~/:/database -e DB2INST1_PASSWORD=GD1OJfLGG64HV2dtwK -e LICENSE=accept -p 50000:50000 --privileged=true ibmcom/db2

To break that down a bit, the command will pull the most recent version of the ibmcom/db2 container, name itdb2, and:

  • Creates a database named testdb
  • Mounts ~/ into the container as /database which is where it will create the testdb database (NOTE: if you’re interested in placing your database in a different location — which is probably advisable — just substitute ~/ with some other location. Of course, on Windows you’ll need to substitute this with a Windows friendly path.)
  • Sets the db2inst1 user password set to GD10JfLGG64HV2dtwK (Please change this password to something secure of your choosing)
  • Automatically accepts the user licence
  • Sets the Db2 ports to 50000 inside the container, and maps it to port 50000 outside of the container. If you’d like a different port outside of the container, feel free to change the first 50000.
  • Starts the container in privileged mode

UPDATE: I’ve added --restart unless-stopped to the command above so that on reboot, or docker restart, the container is restarted. If you don’t want this behaviour, feel free to remove that option.

Here’s what it looks like when I run it:

That’s it! And complete in less than 5 minutes.

Of course, behind the scenes, there’s a lot going on. Once the container is pulled, the license is applied, the database is created, and it’s configured for optimal use. You can follow along with what’s going on after the install using the command:

docker logs db2

Once you see this in the logs, your installation is complete:

(*) Setup has completed.

Once the install has completed you can get into the container to run the Db2 CLP using the following command:

docker exec -it db2 bash -c "su - db2inst1"

Of course, once inside the container, you can run all of your favourite Db2 commands:

Happy Db2ing!

Adam Storm

Written by

Adam has been developing and designing complex software systems for the last 15+ years. He is also a son, brother, husband and father.

More From Medium

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade