db2 and docker - db2-aktuell.de für luw/3_db2_db2_and_docker.pdf · ibm cloud hybrid data...

48
IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2 Aktuell 2018 Claus Hümpel Technical Sales, Hybrid Data Management, IBM Germany [email protected] Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Upload: ngoquynh

Post on 20-Nov-2018

249 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux

Db2 Aktuell 2018

Claus Hümpel

Technical Sales, Hybrid Data Management, IBM Germany

[email protected]

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 2: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Legal Disclaimer

• © IBM Corporation 2018. All Rights Reserved.

• The information contained in this publication is provided for informational purposes only. While efforts were made to verify the completeness and accuracy of the information contained in this

publication, it is provided AS IS without warranty of any kind, express or implied. In addition, this information is based on IBM’s current product plans and strategy, which are subject to change

by IBM without notice. IBM shall not be responsible for any damages arising out of the use of, or otherwise related to, this publication or any other materials. Nothing contained in this

publication is intended to, nor shall have the effect of, creating any warranties or representations from IBM or its suppliers or licensors, or altering the terms and conditions of the applicable

license agreement governing the use of IBM software.

• References in this presentation to IBM products, programs, or services do not imply that they will be available in all countries in which IBM operates. Product release dates and/or capabilities

referenced in this presentation may change at any time at IBM’s sole discretion based on market opportunities or other factors, and are not intended to be a commitment to future product or

feature availability in any way. Nothing contained in these materials is intended to, nor shall have the effect of, stating or implying that any activities undertaken by you will result in any specific

sales, revenue growth or other results.

• Performance is based on measurements and projections using standard IBM benchmarks in a controlled environment. The actual throughput or performance that any user will experience will

vary depending upon many factors, including considerations such as the amount of multiprogramming in the user's job stream, the I/O configuration, the storage configuration, and the workload

processed. Therefore, no assurance can be given that an individual user will achieve results similar to those stated here.

• IBM, the IBM logo, Lotus, Lotus Notes, Notes, Domino, Quickr, Sametime, WebSphere, UC2, PartnerWorld and Lotusphere are trademarks of International Business Machines Corporation in

the United States, other countries, or both. Unyte is a trademark of WebDialogs, Inc., in the United States, other countries, or both.

• Java and all Java-based trademarks and logos are trademarks or registered trademarks of Oracle and/or its affiliates.

• Microsoft and Windows are trademarks of Microsoft Corporation in the United States, other countries, or both.

• Intel, Intel Centrino, Celeron, Intel Xeon, Intel SpeedStep, Itanium, and Pentium are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other

countries.

• UNIX is a registered trademark of The Open Group in the United States and other countries.

• Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both. Other company, product, or service names may be trademarks or service marks of others.

• Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. in the United States and/or other countries. Docker, Inc. and other parties may also have trademark rights

in other terms used herein.

• Mac and macOS are trademarks of Apple Inc., registered in the U.S. and other countries.

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 3: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

• Containers and Docker

• Installing Docker

• Your First Db2 Container

• Advanced Topics

• Summary

Agenda

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 4: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

What is a Container?

VirtualMachine

Container

Containers are isolated,but share OS and, whereappropriate, bins/libraries

...result is significantly faster deployment,much less overhead, easier migration,faster restart.

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 5: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Why Containerization?

• Portability („containerize once, run anywhere“)• One-can-fit-it-all (no local Db2 installation needed any longer)

• Can be used also for test and development environments.

• Lower foot-print, higher density• Less Virtual Machines

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 6: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Docker Container Management

Docker CLI/API Interface to control the Docker Engine

Docker Engine Container runtime management and image build services

Docker Registry Public or Private Image management and versioning services

Docker Hub Public Docker image registries with curated content

App A App B1 App B2

Bins & Libs Bins & Libs

Docker Engine

Host OS (Linux)

Server HWimages

Public / Private DockerRegistry

DockerHub

Self-hosted Docker Image

Registry

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 7: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Working with Docker

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 8: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

• Containers and Docker

• Installing Docker

• Your First Db2 Container

• Advanced Topics

• Summary

Agenda

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 9: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Docker Distributions

• Docker for Windows• Desktop application• Requires 64bit Windows 10 Pro, Enterprise or Education• Uses Microsoft Hyper-V virtualization and MobyLinux VM• Uses Docker CE

• Docker for Mac• Desktop application• Requires OS X El Capitan 10.11 or newer macOS release• Uses macOS virtualization and HyperKit VM• Uses Docker CE

• Docker Toolbox (legacy)• Desktop application• For older Mac and Windows systems• Requires 64bit Windows 7 or higher (on Windows-PC)• Requires OS X Mountain Lion 10.8 or higher (on Mac)• Uses Oracle VirtualBox virtualization and Linux VM• Uses Docker CE

• Docker on Linux• Server application

• Requires Linux kernel 3.10 (update to latest kernel rec.)

• Native, uses Linux kernel capabilities (control groups, namespaces)

• Supported HW platforms

• Intel & AMD (x86_64 / amd64), ARM

• IBM Power (ppcle64)

• IBM Z (s390x)

• Can be run on Linux host (bare-metal) or in a Linux VM on Hyper-V, KVM, Nutanix, PowerVM, Red Hat Virtualization, VMWare, etc.

• Docker on Linux Editions• Docker Community Edition (CE)

• CentOS, Debian, Fedora, Ubuntu, Binary• Docker Enterprise Edition (EE)

• CentOS, Oracle Linux, RHEL, SLES, Ubuntu, Microsoft Windows Server (2016, 1709, 1803)

• Docker Engine (1.13 and earlier)• Legacy, superseeded by Docker CE and Docker EE

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 10: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Docker StoreCreate a Docker ID1. Open a web browser and go to

https://store.docker.com

2. Click Log In.

3. Click Create Account.

4. Enter your Docker ID, Email and Password.

5. Check the two I agree ... check-boxes. Check I‘m not a robot...

6. Click Sign Up.

2.

3.

4.

6.

1.

5.

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 11: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Docker for WindowsInstallation• https://store.docker.com/editions/community/do

cker-ce-desktop-windows

• Requires 64-bit Windows 10 Professional, Enterprise or Education.

• 1607 Anniversary Update, Build 14393 or later

• Uses Windows Hyper-V virtualization.• After Hyper-V is enabled, Oracle VirtualBox / VMWare

Workstation no longer work but any VirtualBox / VMWareimage remain.

• To disable / enable Hyper-V, open an elevated Command Prompt and type either:

• bcdedit /set hypervisorlaunchtype off

• bcdedit /set hypervisorlaunchtype auto

• Reboot

• If your system does not meet the requirements, you can install Docker Toolbox instead.

• Docker Toolbox uses Oracle VirtualBox instead ofHyper-V.

1.

2.

3.4.

5.

6. 7. 8.

9.

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 12: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Docker for WindowsGet Started

(1) Verify Docker. Open a terminal window and type:

docker run hello-world (2) Docker Settings. Right-click the Whale icon in thetray-bar and select Settings

(3) General tab. Uncheck Send usage statistics option

eventually.

(6) Advanced tab. Change the number of processors and amount of memory assigned to the Linux VM if

necessary. Default is 2 CPU coresand 2 GB RAM

(4) Shared Drives tab. Share your local drives (volumes) with Docker for

Windows, so that they are available to your Linux containers. Can be done

on-demand, too.

(5) Firewall detected. Allowconnections to 10.0.75.1 on port 445 (the Windows host) from 10.0.75.2

(the virtual machine) in yourWindows PC firewall.

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 13: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Docker for MacInstallation• https://store.docker.com/editions/community

/docker-ce-desktop-mac

• Requires macOS Yosemite 10.10.3 or above

• Uses native virtualization and HyperKit VM

• Similar look and feel as on Windows.

• If your system does not meet therequirements, install Docker Toolbox instead.

• Docker Toolbox uses Oracle VirtualBox.

3.

2.

1.

4.

5. 6. 7.

8.

9.

10.

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 14: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Docker for MacGet Started

(2) Docker Settings. Right-click the whale icon in the

top status bar and clickPreferences

(3) General tab. Uncheck Send usage statistics option

eventually.

(4) File Sharing tab. Share your local drives (volumes) with Docker for Mac, so that they are available to your Linux containers. /Users, /Volumes, /private and /tmp are

exported by default.

(6) Advanced tab. Change the number of processors and amount of memory assigned to the Linux VM if

necessary. Default is 2 CPU cores and 4 GB RAM (3.8 GiB)

(6) Disk tab. Modify the diskimage size of the Linux VM if

necessary. Default size is 64 GB.

(1) Verify Docker. Open a Terminal and type:

docker run hello-world

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 15: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Docker on Linux – Docker CEInstallation on Ubuntu/CentOS1. Uninstall old versions

• sudo apt-get remove docker docker-engine docker.io # Ubuntu

• sudo yum remove docker docker-client docker-client-latestdocker-common docker-latest docker-latest-logrotatedocker-logrotate docker-selinux docker-engine-selinuxdocker-engine # CentOS

2. Download and run the installation script (*)

• curl -fsSL https://get.docker.com -o get-docker.sh

• sudo sh get-docker.sh

3. Give your Linux user sudo rights to run docker commands.Logoff and login to make changes effective.• sudo usermod -aG docker <your-user>

4. (Optional) Upgrade your Linux distribution.• sudo apt-get update && sudo apt-get upgrade # Ubuntu

• sudo yum update && sudo yum upgrade # CentOS

5. Startup the Docker daemon and enable automatic startup.• sudo systemctl start docker && sudo systemctl enable docker

6. Verify the installation• docker run-hello world

(*) Not recommended for production environments. Install using the repository or from a package instead.

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 16: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Docker Toolbox for WindowsInstallation• https://download.docker.com/win/stable/

DockerToolbox.exe

• Requires 64-bit Windows 7 or higher• Make sure that virtualization is enabled on your

machine. See this link to verify.

• Installs• Docker Client for Windows• Docker Toolbox management tool and ISO• Oracle VM VirtualBox• Git MSYS-git UNIX tools

• Uses Oracle VirtualBox virtualization.

• Creates one Linux VM as your Docker host.• More VMs can be created (via docker-machine

command).• This allows you to run multiple Docker hosts on

your Windows host.

• Legacy desktop solution.• Docker Toolbox is for older Mac and Windows

systems that do not meet the requirements of Docker for Mac and Docker for Windows.

• Docker recommends updating to the newer applications, if possible.

1.2.

3.

4. 5. 6.

7. 8.

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 17: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Docker Toolbox for WindowsGet Started

1.

(1) Verify Docker. Click the Docker QuickStart icon to launch a pre-

configured Docker Toolbox terminal.If the system displays a User Account Control prompt to allow VirtualBox to make changes to your computer.

Choose Yes.

(2) The terminal does several things to set up Docker Toolbox for you.

When it is done, the terminal displays

the $ prompt.

2.

3.

(3) Type docker run hello-world

command and press RETURN

(4) The command does some work

for you, if everything runs

well, the command’s output

looks like this:

4.

(9) Shared Folders tab. Share your local drives

with Docker Toolbox, so that they are available to your Linux container. The C:\Users folder is shared

by default.

(8) Processor tab. Change the number of processors of the Linux VM. The default is

1 processor core

(7) Motherboard tab. Change the amount of

memory for the Linux VM. The default is

1024 MB

(5) Settings. Click the Oracle VM VirtualBox icon to launch

VirtualBox manager.

(6) During Step 2 Docker Toolbox created a Linux VM named default. This is your

Docker host. Click the Settings button to open the Settings

pop-up window.

5.

6.7. 8.

9.

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 18: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

• Containers and Docker

• Installing Docker

• Your First Db2 Container

• Advanced Topics

• Summary

Agenda

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 19: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Get the free Db2 Developer-C Edition Containerfrom the Docker Store

1. Open a web browser and enter the URL https://store.docker.com

2. Click Log In.

3. Enter your Docker ID and your password. Click Login.

4. Search for Db2

5. Click Show all 6 hits in Store

6. Scroll down and clickDb2 Developer-C Edition

7. Click Proceed to Checkout

8. Enter your Contact Information,check I agree… and I acknowledge…

9. Click Get Content

10. (Optional) Review the Setup Instructions.

2.1.

4.

5.

6.

7.

8.8.

9.

[email protected]

3.

3.

10.

10.

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 20: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Deploy your Db2 Container in 7 Steps1. Open a terminal and login to the Docker Hub registry.

• docker login

• Enter your Docker ID and your password.

2. Pull the Db2 container from the registry.• docker pull store/ibmcorp/db2_developer_c:11.1.3.3b-x86_64

3. Create an .env_list configuration file (see next slide).

4. Create a volume where the Db2 container stores database, configuration and transaction log files.• docker volume create db2server_vol

5. Deploy the Db2 container• docker run –h db2server –-name db2server –-restart=always–-detach –-privileged=true –p 50000:50000 –p 55000:55000–-env-file=.env_list–v db2server_vol:/databasestore/ibmcorp/db2_developer_c:11.1.3.3b-x86_64

6. View the deployment logs and look for the message (*) Setup has completed.• docker logs –-follow db2server

7. Log on to the container and switch to Db2 instance user. Connect to your database.• docker exec –ti db2server bash –c "su – db2inst1"

• db2 connect to testdb

Name of the current Db2 Developer-C Container image. Name changes upon a new version.

Db2 11.1.3.3 iFix 002 engine. Db2 HADR support.Multi-platform support: x86_64, ppc64le, s390x

The extension specifies the platform.

Instead of a volume you can use a bind mountthat points to a shared directory on your host.

Replace in the docker run cmd-v db2server_vol:/database by e.g

-v c:/database:/database

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 21: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Deploy your Db2 Container

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 22: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

The .env_list Configuration FileLICENSE=acceptDB2INSTANCE=db2inst1DB2INST1_PASSWORD=passwordDBNAME=testdbBLU=falseENABLE_ORACLE_COMPATIBILITY=falseUPDATEAVAIL=NOTO_CREATE_SAMPLEDB=falseREPODB=falseIS_OSXFS=falsePERSISTENT_HOME=falseHADR_ENABLED=falseETCD_ENDPOINT=ETCD_USERNAME=ETCD_PASSWORD=

• LICENSE is to agree to the terms and conditions of the Db2 software contained in this image• DB2INSTANCE is to specify the Db2 Instance name• DB2INST1_PASSWORD is to specify the respective Db2 Instance Password• DBNAME creates an initial database with the name provided or leave empty if no database

is needed• BLU can be set to true to enable BLU Acceleration for instance• ENABLE_ORACLE_COMPATIBILITY can be set to true to enable Oracle Compatibility on the

instance• UPDATEAVAIL can be set to yes if there is an existing instance and running a new container

with a higher Db2 level. Will be deprecated on next release• TO_CREATE_SAMPLEDB can be set to true to create a sample (pre-populated) database• REPODB can be set to true to create a Data Server Manager repository database• Set IS_OSXFS=true if you are running on macOS • PERSISTENT_HOME is true by default, only specify to false if you are running Docker for

Windows • HADR_ENABLED if set to true, Db2 HADR will be configured. The following three env

variables depend on HADR_ENABLED to be true • ETCD_ENDPOINT is for specifying your own provided ETCD key-value store. Enter your

endpoints with a comma as the delimiter and without a space. This env variable is needed if HADR_ENABLED is set to true

• ETCD_USERNAME specify the username credential for ETCD. If empty, it will use your Db2 instance

• ETCD_PASSWORD specify the password credential for ETCD. If empty, it will use your Db2 instance password

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 23: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Data Persistency – the /database directory• /database

• /backup

• TESTDB.0.db2inst1.DBPART000.20180921192410.001

• /config

• /db2fenc1

• /db2inst1

• /sqllib

• /db2dump

• /DIAG0000

• db2diag.log

• global.reg

• instance.cfg

• /licenses

• /database

• /data

• /db2inst1

• /NODE0000

• /SQL00001

• /TESTDB

• /sqldbdir

• /logs

• /db2inst1

• /TESTDB

• /NODE0000

• /LOGSTREAM0000

• /C0000000

• S0000001.log

• S0000002.log

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 24: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Volume Sharing (bind mounts)

• Volume sharing to share a common directory between the container and the host• Could be used to

• exchange information

• store persistent information

docker run –h db2server –-name db2server –-restart=always

–-detach –-privileged=true –p 50000:50000 –p 55000:55000

–-env-file=.env_list

–v c:/database:/database

store/ibmcorp/db2_developer_c:11.1.3.3b-x86_64

C:\database

/database

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 25: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Port Mapping

• Mapping ports enable to publish a container‘s ports on „external interfaces“.• Ports may be translated

• Use the option –p of the docker run command• docker run –p <external_port>:<internal_port> ...

• Useful when several containers using the same image run on the same host.• Allows each container to use a different port to connect

to the internal port• Avoids to change each container‘s configuration• Facilitates scaling

docker run –h db2server –-name db2server –-restart=always

–-detach –-privileged=true –p 50000:50000 –p 55000:55000 […]

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 26: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

• Containers and Docker

• Installing Docker

• Your First Db2 Container

• Advanced Topics

• Summary

Agenda

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 27: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Applying a Db2 License File

• Your Db2 container is limited to the license conditions of the Db2 Developer-C Edition:

• 16 GB of RAM maximal

• 4 cores maximal

• 100 GB maximal database size

• Community support only, no service requests or PMRs can be opened.

• You can upgrade the Db2 container to a higher level, fully supported Db2 version if needed.

• Copy your license file into the Db2 container and use the db2licm –a command to add your license.

• Example for upgrading to Db2 Enterprise Server Edition:• docker cp .\db2ese_c.lic db2server:/tmp

• docker exec –ti db2server bash

• su – db2inst1

• db2licm –a /tmp/db2ese_c.lic

• db2licm –l

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 28: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Backup and Restore• Backup

• docker exec –it db2server bash

• su – db2inst1

• db2 backup database testdb online to /database/backup compress include logs

• db2ckbkp <location/backup file>

• Restore• docker exec –it db2server bash

• su – db2inst1

• db2 deactivate database testdb

• db2 restore database testdb from /database/backup taken at <timestamp>

• db2 rollforward db testdb to end of logs and stop

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 29: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Upgrading• Stop and rename the container

• docker stop db2server

• docker rename db2server db2server_org

• Redeploy the container using the new image

• docker run –h db2server –-name db2server

–-restart=always

–-detach –-privileged=true

–p 50000:50000 –p 55000:55000

–-env-file=.env_list

–v db2server_vol:/database

store/ibmcorp/db2_developer_c:11.1.3.3b-x86_64

• Verify logs

• docker logs –follow db2server

• Enter into the container

• docker exec –it db2server bash –c " su – db2inst1 "

• Catalog your database and connect

• db2 catalog database testdb

• db2 connect to testdb

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 30: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Automation with Dockerfile

• You can automate the setup of your Db2 container by providing a custom Dockerfile and building your own image based on the official Db2 Developer-C continer.

• The Dockerfile would include steps to add-in your Db2 license file.

• Additionally, you can copy user-provided scripts into the container that will be run after the setup of the Db2 container has finished.

• E.g. for creating tables, restoring the database from a backup etc.

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 31: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Automation ExampleFROM store/ibm/db2_developer_c:11.1.3.3b-x86_64

# copy Db2 ESE license file into containerCOPY ./db2ese_c.lic /var/db2_setup/include/db2dec.lic

# copy custom script into directory for user-provided scriptsCOPY ./my_custom_script.sh /var/custom/my_custom_script.sh

#!/bin/bashecho "##############################"echo "#### BEGIN CUSTOM SCRIPT #####"echo "##############################"su – db2inst1 –c "db2licm –r db2dec"su – db2inst1 –c "db2licm –l"echo "##############################"echo "#### END CUSTOM SCRIPT #####"echo "##############################"

my_custom_script.sh:

Dockerfile:1. Build the custom image my_image:

• docker build –rm –t my_image .

2. Deploy the Db2 container• docker run –h db2server2 –-name

db2server2 –-restart=always

–-detach –-privileged=true

–p 50000 –p 55000

–-env-file=.env_list

–v db2server2_vol:/database

my_image

3. View the deployment logs• docker logs –-follow db2server2

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 32: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

HADR Setup

LICENSE=acceptDB2INSTANCE=db2inst1DB2INST1_PASSWORD=passwordDBNAME=testdbBLU=falseENABLE_ORACLE_COMPATIBILITY=falseUPDATEAVAIL=NOTO_CREATE_SAMPLEDB=falseREPODB=falseIS_OSXFS=falsePERSISTENT_HOME=falseHADR_ENABLED=trueETCD_ENDPOINT=10.0.75.2:7001,

10.0.75.2:7002,10.0.75.2:7003ETCD_USERNAME=ETCD_PASSWORD=

.env_list_hadr:1. Primary• docker run -h db2server3

--name db2server3 --restart=always

--detach --privileged=true

--ipc=host -p 50000 -p 55000

--env-file .env_list_hadr

-v db2server3_vol:/database -v nfs_vol:/hadr

store/ibmcorp/db2_developer_c:11.1.3.3b-x86_64

2. Standby• docker run -h db2server4

--name db2server4 --restart=always

--detach --privileged=true

--ipc=host -p 50000 -p 55000

--env-file .env_list_hadr

-v db2server4_vol:/database -v nfs_vol:/hadr

store/ibmcorp/db2_developer_c:11.1.3.3b-x86_64

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 33: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

HADR Setup (continued)3. Volumes

• docker volume create db2server3_vol

• docker volume create db2server4_vol

• docker volume create nfs_vol

4. etcd (three node cluster)• docker run -d -p 5001:5001 -p 7001:7001 --name node1 --restart=always quay.io/coreos/etcd:v2.3.8 -name node1 -advertise-client-urls http://10.0.75.2:7001 -listen-client-urls http://0.0.0.0:7001 -initial-advertise-peer-urlshttp://10.0.75.2:5001 -listen-peer-urls http://0.0.0.0:5001 -initial-cluster-token etcd-cluster-1 -initial-cluster node1=http://10.0.75.2:5001,node2=http://10.0.75.2:5002,node3=http://10.0.75.2:5003

• docker run -d -p 5002:5002 -p 7002:7002 --name node2 --restart=always quay.io/coreos/etcd:v2.3.8 -name node2 -advertise-client-urls http://10.0.75.2:7002 -listen-client-urls http://0.0.0.0:7002 -initial-advertise-peer-urlshttp://10.0.75.2:5002 -listen-peer-urls http://0.0.0.0:5002 -initial-cluster-token etcd-cluster-1 -initial-cluster node1=http://10.0.75.2:5001,node2=http://10.0.75.2:5002,node3=http://10.0.75.2:5003

• docker run -d -p 5003:5003 -p 7003:7003 --name node3 --restart=always quay.io/coreos/etcd:v2.3.8 -name node3 -advertise-client-urls http://10.0.75.2:7003 -listen-client-urls http://0.0.0.0:7003 -initial-advertise-peer-urlshttp://10.0.75.2:5003 -listen-peer-urls http://0.0.0.0:5003 -initial-cluster-token etcd-cluster-1 -initial-cluster node1=http://10.0.75.2:5001,node2=http://10.0.75.2:5002,node3=http://10.0.75.2:5003

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Note, run the steps – (3) Volumes and (4) etcd – before the steps (1) Primary

and (2) Standby from the previous slide.

Page 34: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

HADR Setup (continued)

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 35: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

HADR Setup (continued)

PRIMARY STANDBY

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 36: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

• Containers and Docker

• Installing Docker

• Your First Db2 Container

• Advanced Topics

• Summary

Agenda

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 37: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Summary

• We have shown the basics of containers and Docker and why running Db2 software in a Docker container makes sense.

• You have seen how to install Docker on Windows, macOS and Linux.

• You have learned how to setup your first Db2 Docker container.

• We have shown advanced topics such as Licensing, Backup / Restore, Upgrade, Automation with a Dockerfile and a Db2 HADR setup.

• LET‘S START USING Db2 ON DOCKER !!!

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 38: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Additional Ressources

• Docker Documentation• https://docs.docker.com/

• dW Article on building and deploying Db2 Docker containers• https://www.ibm.com/developerworks/data/library/techarticle/dm-1602-

db2-docker-trs/index.html

• ZDNet Article „What is Docker and why is it so darn popular?“• https://www.zdnet.com/article/what-is-docker-and-why-is-it-so-darn-

popular/

• IBM Softlayer free cloud server for one month (Ubuntu, CentOS)• https://www.softlayer.com/promo/free-cloud/

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 39: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Contact

Claus Hümpel

Technical Sales Professional – Hybrid Data Management

IBM Germany, Düsseldorf

[email protected]

+49-177-362-7278

ibm.com

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 40: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 41: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

BACKUP SLIDES

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 42: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

What is a Container?Containers are a lightweight alternative to Virtual Machines for running

software in portable and isolated virtual environments

Attribute VM Container

Start-up time & Performance Slow (minutes) HV overhead Fast (seconds) no HV overhead

Footprint Large (nothing shared) Small (OS kernel shared)

Resource Constraints Yes Yes (CPU, Memory)

Isolation & Security High High

Portability Low High

Traditional Virtualization Approach

App A App B1 App B2

Bins & Libs Bins & Libs Bins & Libs

Guest OS(RHEL)

Guest OS(RHEL)

Guest OS(RHEL)

Hypervisor

Server HW

VMs

App A App B1 App B2

Bins & Libs Bins & Libs

Host OS(RHEL)

Server HW

Docker Container Approach

Hypervisor OPTIONAL

Containers

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 43: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

What is a Container? (continued …)

Ap

p A

Host OS

Server

Bins/Libs

Ap

p A

Bins/Libs

Ap

p B

Ap

p B

Ap

p B

Ap

p B

Container

What is a Container• An isolated user space within a running Linux OS

• Immutable – container environment will not change across stop/start

• Shared kernel across containers

• Direct device access

• All packages and data in an isolated run-time, saved as a filesystem

• Resource management implemented with Linux Control Groups ( Cgroups )

• Resource isolation through Linux namespaces ( currently 6 implemented )

Run

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 44: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Docker Engine

A portable, lightweight application runtime and packaging tool

built on top of kernel container primitives

Build Ship Run

Docker Engine▪ Open source project

▪ Supported on every major Linux distro (min kernel 3.10), MS Windows and Mac -- running on a Tiny Core

Linux boot2docker VM or using native support (since Windows 10)

▪ Client-server architecture with daemon deployed on physical or virtual host

▪ Uses Linux kernel cgroups and namespaces for process resource management and isolation

▪ Uses copy-on-write filesystem for git-like image change management

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 45: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Docker Hub / Docker Store

▪ Enable sharing and collaboration of Docker Images

▪ Private and public repositories of images

▪ Certified base images by ISVs

Ship

Docker Hub

$ docker push $ docker pull

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 46: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Docker for Windows Architecture• Docker is based on Linux

• In order to run Docker on Windows, as of today some tricks are needed.

• The base for Docker for Windows is a minimal Linux-system (MobyLinux) that runs in Windows under Hyper-V. Hyper-V is the virtualization technology from Microsoft.

• All images, containers and data of the Docker installation are placed in one large .vhdx-file, that can grow and shrink dynamically.

• The individual containers (Db2, WAS, etc.) are isolated from each other, but all access the same Linux kernel from MobyLinux.

• In addition, data volumes exist that allow to persist data (DB + config) even when the container is deleted.

Imag

e: c

‘t 5

/18

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 47: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management

Db2 Developer-C Edition – Docker vs. Non-Docker

OUTDATED DONT‘USEDONWLOAD FROM DOCKER STORE

Non-Docker Version

Docker Version

Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation

Page 48: Db2 and Docker - db2-aktuell.de für LUW/3_Db2_Db2_and_Docker.pdf · IBM Cloud Hybrid Data Management Db2 and Docker - Getting Up and Running on Windows, OS X (macOS) and Linux Db2

IBM Cloud Hybrid Data Management Db2 Aktuell / Sep 25, 2018 / © 2018 IBM Corporation