SlideShare a Scribd company logo
1 of 57
Download to read offline
Copyright 2017 Severalnines AB
I'm Jean-Jérôme from the Severalnines Team and
I'm your host for today's webinar!
Feel free to ask any questions in the Questions
section of this application or via the Chat box.
You can also contact me directly via the chat box
or via email: info@severalnines.com during or
after the webinar.
Your host & some logistics
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
About Severalnines and ClusterControl
Copyright 2017 Severalnines AB
What We Do
Copyright 2017 Severalnines AB
ClusterControl Automation & Management
Management
● Multi-Cluster / Multi-DC
● Automate Repair &
Recovery
● Database Upgrades
● Backups
● Configuration Management
● Database Cloning
● One-Click Scaling
Deployment
● Deploy a Cluster in Minutes
● On-Premises or in the Cloud (AWS)
Monitoring
● Systems View with 1sec Resolution
● DB / OS stats & Performance Advisors
● Configurable Dashboards
● Query Analyzer
● Real-time / historical
Copyright 2017 Severalnines AB
Supported Databases
Copyright 2012 Severalnines ABCopyright 2012 Severalnines AB
Our Customers
Sep 2017
MySQL on Docker:
Understanding the Basics
Ashraf Sharif, Support Engineer
Presenter
ashraf@severalnines.com
Agenda
Copyright 2012 Severalnines AB
● Introduction
● Image
● Container
● Volume
● Network
● Orchestration
● ClusterControl on Docker
● Q&A
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
Introduction
What is Docker?
Copyright 2012 Severalnines AB
● Lightweight application container platform.
● Each container has its own:
○ Filesystem
○ Process space
○ Network stack
● Use pre-built image.
● Advantages:
○ Rapid deployment
○ Greater density per host
○ Isolation
Docker Architecture
Docker Components
Copyright 2012 Severalnines AB
Docker Components
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
Docker Image
Docker Image - Introduction
Copyright 2012 Severalnines AB
● A template for Docker container.
● Create an image:
○ Commit the container's changes
○ Build from Dockerfile
● Share the image:
○ Save as tarball.
○ Push to registry:
■ Public - Docker Hub, Docker Store
■ Private, hosted - Quay, ECR, GCR, Bintray,
Artifactory
■ Private, self-hosted - Your own registry
# Save image to tarball
$ docker save -o mysql.tar abc
# Start your own Docker registry service
$ docker run -d -p 5000:5000 --name registry
registry:2
# Push image to Docker Hub
$ docker push myimage/mysql:5.7
Docker Image - Commit a Container
Copyright 2012 Severalnines AB
Host
# Save image to tarball
$ docker run -d --name=abc ubuntu:16.04
# Commit the changes (in another window)
$ docker commit abc myimage/mysql:5.7
# Push image to Docker Hub
$ docker exec -it abc /bin/bash
root@abc:/# apt-get update
root@abc:/# DEBIAN_FRONTEND=noninteractive apt-get
install -y mysql-server
root@abc:/# vi /etc/mysql/my.cnf
# Ubuntu 16.04 host
$ apt-get update
$ DEBIAN_FRONTEND=noninteractive apt-get install -y
mysql-server
$ vi /etc/mysql/my.cnf
# Run MySQL server as a process
$ mysqld --socket=/var/lib/mysql/mysqld.sock
--pid-file=/var/lib/mysql/mysqld.pid
Docker
# Run MySQL server as a container
$ docker run -d myimage/mysql:5.7 mysqld
--socket=/var/lib/mysql/mysqld.sock
--pid-file=/var/lib/mysql/mysqld.pid
Docker Image - Using Dockerfile
Copyright 2012 Severalnines AB
Host
# Build as image
$ docker build -t myimage/mysql:5.7 .
# vi Dockerfile
FROM ubuntu:16.04
RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y
mysql-server
COPY my.cnf /etc/mysql/my.cnf
EXPOSE 3306
# Ubuntu 16.04 host
$ apt-get update
$ DEBIAN_FRONTEND=noninteractive apt-get install -y
mysql-server
$ vi /etc/mysql/my.cnf
# Run MySQL server as a process
$ mysqld --socket=/var/lib/mysql/mysqld.sock
--pid-file=/var/lib/mysql/mysqld.pid
Docker
# Run MySQL server as a container
$ docker run -d myimage/mysql:5.7 mysqld
--socket=/var/lib/mysql/mysqld.sock
--pid-file=/var/lib/mysql/mysqld.pid
# Create MySQL config file
$ vi my.cnf
Docker Image - Build an Image
Copyright 2012 Severalnines AB
# Get image size
$ docker images
REPOSITORY TAG SIZE
myimage/mysql 5.7 529MB
# Show created layers
$ docker history myimage/mysql:5.7
CREATED BY SIZE
/bin/sh -c #(nop) COPY file:e8163ef656b6da... 101B
/bin/sh -c DEBIAN_FRONTEND=noninteractive ... 370MB
/bin/sh -c apt-get update 39.1MB
/bin/sh -c #(nop) CMD ["/bin/bash"] 0B
/bin/sh -c mkdir -p /run/systemd && echo '... 7B
/bin/sh -c sed -i 's/^#s*(deb.*universe... 2.76kB
/bin/sh -c rm -rf /var/lib/apt/lists/* 0B
/bin/sh -c set -xe && echo '#!/bin/sh' >... 745B
/bin/sh -c #(nop) ADD file:39d3593ea220e68... 120MB
de70fa77eb2b
f6016aab25f1
0639788facc8
35369f9634e1
937bbdd4305a
724179e94999
f6016aab25f1
d51f459239fb
Image: myimage/mysql:5.7
ubuntu:16.04
ad74af05f5a2
Dockerfile
Docker Image - Best Practice for MySQL
Copyright 2012 Severalnines AB
# Get image size
$ docker images
REPOSITORY TAG SIZE
mysql 5.6 299MB
mysql 5.7 412MB
# tail entrypoint.sh
...
...
exec mysqld "$@"
● Extend an existing image available in the registry,
instead of building a new one from scratch.
● The smaller the image size, the faster the deployment.
(Hint: alpine).
● If using an entrypoint script, ensure mysqld command
runs with "exec", indicating it's the primary process
that holds PID 1 inside container.
● General guidelines:
https://docs.docker.com/engine/userguide/eng-image/
dockerfile_best-practices/
# vi Dockerfile
FROM mysql:5.7
# vi Dockerfile
FROM ubuntu:16.04
RUN apt-get install {all MySQL stuff}
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
Docker Container
Docker Container - Run a Single
Container
Copyright 2012 Severalnines AB
# Run a MySQL container
$ docker run -d 
--name my-test 
--env MYSQL_ROOT_PASSWORD=mypassword 
mysql
# Get the container layer size
$ docker ps -s
CONTAINER ID IMAGE NAMES SIZE
d51f459239fb mysql my-test 4B (virtual 412MB)
Image: docker.io/mysql:latest
de70fa77eb2b
f6016aab25f1
0639788facc8
35369f9634e1
937bbdd4305a
ad74af05f5a2
d51f459239fb
0639788facc8
35369f9634e1
937bbdd4305a
my-test
Image layers
(RO)
412 MB
Container layers
(RW)
4 B
Docker Container - Run another
Container
Copyright 2012 Severalnines AB
# Run a MySQL container
$ docker run -d 
--name my-test2 
--env MYSQL_ROOT_PASSWORD=mypassword 
mysql
# Get the container layer size
$ docker ps -s
CONTAINER ID IMAGE NAMES SIZE
d51f459239fb mysql my-test 4B (virtual 412MB)
e9de9ed50ced mysql my-test2 4B (virtual 412MB)
Image: docker.io/mysql
de70fa77eb2b
f6016aab25f1
0639788facc8
35369f9634e1
937bbdd4305a
ad74af05f5a2
d51f459239fb
0639788facc8
35369f9634e1
937bbdd4305a
my-test
Image layers
(RO)
412 MB
Container
layers (RW)
4 B + 4 B
e9de9ed50ced
my-test2
Docker Container - Container Layer
Changes
Copyright 2012 Severalnines AB
# Operation 2 - Create a schema and table
$ docker exec -it my-test 
mysql -uroot -pmypassword -e 
'CREATE SCHEMA testdb; CREATE TABLE t1 (id INT PRIMARY
KEY AUTO_INCREMENT, data TEXT);'
Image: docker.io/mysql
de70fa77eb2b
f6016aab25f1
0639788facc8
35369f9634e1
937bbdd4305a
ad74af05f5a2
d51f459239fb
0639788facc8
35369f9634e1
937bbdd4305a
my-test
c33a2b88395d
Copy-on-Write
(CoW)
416f2a97355f
Supported CoW file system & devices:
AUFS, Btrfs, Device Mapper, OverlayFS/Overlay2, ZFS, VFS
# Operation 1 - Update /etc/mysql/my.cnf
$ docker exec -it my-test vi /etc/mysql/my.cnf
1
2New
Branch
Docker Container - Application vs Data
Copyright 2012 Severalnines AB
Application Data
Stateless Stateful
Ephemeral Persistent
Independant Dependant
Frontend Backend
Web, API Database, File Storage
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
Docker Volume
Docker Volume - Type
Copyright 2012 Severalnines AB
# Mount a named volume into container
-v mysql1-data:/var/lib/mysql
# Mount tmpfs into container
--tmpfs /tmp
● Bind mount:
○ A file or directory on the host machine is
mounted into a container.
○ You manage the directory’s contents.
● Named volume:
○ A new directory is created within Docker’s
storage directory.
○ Docker manages the directory’s contents.
○ Extensible via volume plugin.
● tmpfs:
○ Stored on host machine’s memory (or swap).
○ Linux only.
# Bind mount a directory into container
-v /data/mysql1/data:/var/lib/mysql
# Bind mount a file into container
-v /data/mysql1/my.cnf:/etc/mysql/my.cnf
Docker Volume - Persistent
Volumes
Copyright 2012 Severalnines AB
# Run with persistent named volume, using -v or --volume
$ docker run -d 
--name mysql-local 
--env MYSQL_ROOT_PASSWORD=mypassword 
--volume local-datadir:/var/lib/mysql 
mysql:5.7
Image: docker.io/mysql:5.7
de70fa77eb2b
f6016aab25f1
0639788facc8
35369f9634e1
937bbdd4305a
ad74af05f5a2
0639788facc8
35369f9634e1
937bbdd4305a
mysql-local
416f2a92355f
/var/lib/mysql
local-datadir
# Run with persistent named volume, using --mount
$ docker run -d 
--name mysql-local 
--env MYSQL_ROOT_PASSWORD=mypassword 
--mount source=local-datadir,target=/var/lib/mysql 
mysql:5.7
Docker Volume - Changes on
Volume
Copyright 2012 Severalnines AB
# Run a container with port 3308
$ docker run -d 
--name mysql-local 
-p 3308:3306 
-e MYSQL_ROOT_PASSWORD=mypassword 
-v local-datadir:/var/lib/mysql 
mysql
Image: docker.io/mysql:latest
de70fa77eb2b
f6016aab25f1
0639788facc8
35369f9634e1
937bbdd4305a
ad74af05f5a2
0639788facc8
35369f9634e1
937bbdd4305a
mysql-local
416f2a92355f
/var/lib/mysql
local-datadir
# Run with persistent named volume, using --mount
$ mysql -uroot -p -h127.0.0.1 -P3308 < dump.sql
dump
.sql
3308
Docker Volume - Remote Volume
Copyright 2012 Severalnines AB
# Run a container with NFS bind mount
$ docker run -d 
--name mysql-nfs 
-p 3308:3306 
-e MYSQL_ROOT_PASSWORD=mypassword 
-v /nfs/mysql-nfs:/var/lib/mysql 
mysql
Image: docker.io/mysql
de70fa77eb2b
f6016aab25f1
0639788facc8
35369f9634e1
937bbdd4305a
ad74af05f5a2
0639788facc8
35369f9634e1
937bbdd4305a
mysql-nfs
416f2a92355f
/var/lib/mysql
192.168.1.100
/storage/docker
# Mount NFS with extra options for MySQL
$ mount 192.168.1.100:/storage/docker /nfs -o
noatime,nodiratime,hard,intr
3308
/nfs/mysql-nfs
Further Reading - Using NFS with MySQL:
https://dev.mysql.com/doc/refman/5.7/en/disk-issues.htm
l#disk-issues-nfs
Docker Volume - MySQL Persistency
Copyright 2012 Severalnines AB
Description Variable Name Default Value (5.7)
MySQL data directory datadir /var/lib/mysql
MySQL plugin directory plugin_dir {basedir}/lib/plugin
MySQL configuration directory config_dir /etc/my.cnf.d
MySQL binary log log_bin {datadir}/{hostname}-bin
Slow query log slow_query_log_file {datadir}/{hostname}-slow.log
Error log log_error {datadir}/{hostname}.err
General log general_log_file {datadir}/{hostname}.log
Docker Volume - Non-Persistent
Volume
Copyright 2012 Severalnines AB
# Run a container with NFS bind mount and tmpfs volumes
$ docker run -d 
--name mysql-nfs-tmp 
-p 3308:3306 
-e MYSQL_ROOT_PASSWORD=mypassword 
-v /nfs/mysql-nfs:/var/lib/mysql 
--tmpfs /tmp:rw,size=1g,mode=177 
mysql
Image: docker.io/mysql:latest
de70fa77eb2b
f6016aab25f1
0639788facc8
35369f9634e1
937bbdd4305a
ad74af05f5a2
0639788facc8
35369f9634e1
937bbdd4305a
mysql-nfs-tmp
416f2a92355f
/var/lib/mysql
192.168.1.100
/storage/docker
3308
/nfs/mysql-nfs
/tmp
Docker Volume - Drivers
Copyright 2012 Severalnines AB
● Default is local.
● You can use other different volume driver (or plugin).
○ Install the plugin.
○ Use --volume-driver option.
● Volume drivers allow you to extend Docker's volume
capabilities:
○ Snapshot
○ Backup
○ Encryption
# Install Rexray EBS docker plugin
$ docker plugin install rexray/ebs EBS_ACCESSKEY=XXXX
EBS_SECRETKEY=YYYY
# Verify if the plugin is loaded
$ docker info -f '{{json .Plugins.Volume}}' | jq
[
"local",
"rexray"
]
# Run a container with volume plugin
$ docker run -d 
--name=mysql-ebs 
--volume-driver=rexray/ebs 
-v ebs-datadir:/var/lib/mysql 
mysql:5.7
# List volumes
$ docker volume ls
DRIVER VOLUME NAME
local local-datadir1
local local-datadir2
rexray ebs-datadir
Docker Volume - Drivers and Storage
Platforms
Copyright 2012 Severalnines AB
Further Reading - Volume Plugins List: https://docs.docker.com/engine/extend/legacy_plugins/#volume-plugins
Contiv
Fuxi Netshare
REX-ray
Horcrux
Convoy
OpenStorage
Amazon S3
Azure FS
Google PD
Amazon EBS DigitalOcean
BS
Flocker
EMC
FUSE
vSphere
iSCSI
CIFS NetApp
OpenStack
Cinder Minio CephFS
BeeGFS
NFS
SMB
Infinit
Docker Volume - Simple Benchmark
Copyright 2012 Severalnines AB
Local vs NFS vs NFS-tweaked vs EBS-standard
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
Docker Network
Docker Network - Types
Copyright 2012 Severalnines AB
● Single-host:
○ Host
○ None
○ Bridge
■ Default bridge (docker0)
■ User-defined bridge
● Multi-host:
○ Default overlay
○ User-defined overlay
● Extensible via Docker network plugins.
# List all networks
$ docker network ls
NAME DRIVER SCOPE
bridge bridge local
db_multi overlay swarm
db_single bridge local
docker_gwbridge bridge local
host host local
ingress overlay swarm
none null local
Docker Network - Host Network
Copyright 2012 Severalnines AB
# Run a container on host network
$ docker run -d 
--name mysql-host 
--net host 
-e MYSQL_ROOT_PASSWORD=mypassword 
mysql:5.7
Container 1
eth0
eth0
Container 2
eth0
Docker
Host
# Display active TCP connections
$ netstat -tulpn | grep mysql
tcp6 0 0 :::3306 :::* LISTEN 24601/mysqld
● Container’s network interfaces will be identical with
the machine host.
● Only one host network per machine host.
● Container linking, --link mysql-test:mysql is not
supported.
● Port mapping, --publish 3307:3306 is not
supported.
Docker Network - Default Bridge
Network
Copyright 2012 Severalnines AB
# Run a container on docker0 bridge network
$ docker run -d 
--name mysql-bridge 
-p 3308:3306 
-e MYSQL_ROOT_PASSWORD=mypassword 
mysql:5.7
Container 1
eth0
eth0
Container 2
eth0
Docker
Host
# Display active TCP connections
$ netstat -tulpn | grep 3308
tcp6 0 0 :::3308 :::* LISTEN 24601/docker-proxy
● Packet forwarding by iptables to the bridge network.
● --publish is supported. Run multiple containers with
same image through different ports.
● --link is supported. Link with other containers to
expose environment variables.
● docker-proxy redirects connection to the correct
container through NAT.
docker0
(virtual Ethernet bridge)
vethxxx vethyyy
Docker Network - User-Defined
Bridge Network
Copyright 2012 Severalnines AB
# Run a container on user bridge network
$ docker run -d 
--name mysql1 
--net db_single 
-p 3308:3306 
--ip 192.168.10.10 
--hostname mysql1 
-e MYSQL_ROOT_PASSWORD=mypassword 
mysql:5.7
Container 1
eth0
eth0
Container 2
eth0
Docker
Host
# Create a new bridge network
$ docker network create subnet=192.168.10.0/24 db_single
Similar to the default docker0 bridge, plus:
● --hostname is supported for sticky hostname.
● --ip is supported for sticky IP address.
● --link is not supported. Use embedded DNS to
resolve container's name in the same network.
db_single
(virtual Ethernet bridge)
vethxxx vethyyy
DNS
Docker Network - Plugins
Copyright 2012 Severalnines AB
● Similar to volume, Docker network can be extended
through plugins:
○ Multi-host networking (must use outside of
Swarm)
○ Name resolver and service discovery.
○ Encryption.
● Popular network plugins:
○ Contiv
○ Calico
○ Weave
○ Flannel
Further Reading - Multi-host Networking with Calico:
https://severalnines.com/blog/mysql-docker-multi-host-networkin
g-mysql-containers-part-2-calico
Docker Network - Default Overlay
Network
Copyright 2012 Severalnines AB
# Run a service on default overlay network
$ docker service create 
--name mysql-service 
--replicas 1 
-p 3308:3306 
-e MYSQL_ROOT_PASSWORD=mypassword 
-v nfs-datadir:/var/lib/mysql 
mysql:5.7
Container 1
eth0
eth0 eth1
Docker
Host
# Initialize Docker Swarm
$ docker swarm init
● Docker Swarm must be enabled.
● Each task (container) has:
○ eth0 - Interface to external network via
docker_gwbridge.
○ eth1 - Interface to overlay network via VXLAN.
docker_gw
bridge
vethxxx vethyyy
br0
External
Container 2
eth0 eth1
Docker
docker_gw
bridge
vethxxx vethyyy
br0
eth0
Host
VXLAN
udp/4789
Docker Network - User-Defined
Overlay Network
Copyright 2012 Severalnines AB
# Run a service on default overlay network
$ docker service create 
--name mysql-service 
--replicas 1 
--net db_multi 
-p 3308:3306 
-e MYSQL_ROOT_PASSWORD=mypassword 
-v nfs-datadir:/var/lib/mysql 
mysql:5.7
Container 1
eth0
eth0 eth1
Docker
Host
# Create an overlay network
$ docker network create -d overlay db_multi
Similar with the default overlay, plus:
● Embedded DNS resolver:
○ {service_name} → Service VIP
○ tasks.{service_name} → Container's IP
docker_gw
bridge
vethxxx vethyyy
br0
External
Container 2
eth0 eth1
Docker
docker_gw
bridge
vethxxx vethyyy
br0
eth0
Host
VXLAN
udp/4789
DNS
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
Docker Orchestration
Docker Orchestration - Container
Orchestration
Copyright 2012 Severalnines AB
● Simplify container's management at scale.
● Concept:
○ Multiple containers as one entity.
○ Structural YAML formatting.
● Official Docker comes with:
○ Docker Compose:
■ single-host, small scale, separate package.
○ Docker Swarm:
■ multi-host, big scale, out-of-the-box.
■ support compose formatting through
docker stack.
Docker Orchestration - Docker
Compose
Copyright 2012 Severalnines AB
Docker CLI
version: '2'
services:
mysql-prod:
image: mysql:5.7.16
command:
- --innodb_buffer_pool_size=2G
- --max_connections=50
ports:
- "3307:3306"
environment:
MYSQL_ROOT_PASSWORD: r00tP4ssw0rD
MYSQL_USER: myshop
MYSQL_PASSWORD: MyS3creTP4s5
MYSQL_DATABASE: myshop
hostname: mysql-prod
networks:
db-prod:
ipv4_address: 192.168.10.101
volumes:
- mysql-datadir:/var/lib/mysql
- mysql-tmp:/tmp
ulimits:
nofile:
soft: 16824
hard: 16824
mem_limit: 4g
memswap_limit: 4g
volumes:
mysql-datadir:
mysql-tmp:
networks:
db-prod:
driver: bridge
ipam:
driver: default
config:
- subnet: 192.168.10.0/24
# Production MySQL container - full command
$ docker network create
--subnet=192.168.10.0/24 db-prod
$ docker run -d 
--name mysql-prod 
--net db-production 
--publish 3307:3306 
--ip 192.168.10.101 
--hostname mysql-prod 
--memory 4g 
--memory-swap 4g 
--ulimit nofile=16824:16824 
--volume mysql-datadir:/var/lib/mysql 
--volume mysql-tmp:/tmp 
--env MYSQL_ROOT_PASSWORD=r00tP4ssw0rD 
--env MYSQL_USER=myshop 
--env MYSQL_PASSWORD=MyS3creTP4s5 
--env MYSQL_DATABASE=myshop 
mysql:5.7.16 
--innodb_buffer_pool_size=2G 
--max_connections=50
Docker Orchestration - Run with
Docker Compose
Copyright 2012 Severalnines AB
# Bring up the production MySQL container in background
$ docker-compose up -d
Creating network "compose_db-prod" with driver "bridge"
Creating compose_mysql-prod_1
Image: docker.io/mysql:5.7.18
de70fa77eb2b
f6016aab25f1
0639788facc8
35369f9634e1
937bbdd4305a
ad74af05f5a2
0639788facc8
35369f9634e1
937bbdd4305a
mysql-prod
416f2a92355f
/var/lib/mysql
mysql-datadir
/tmp
mysql-tmp
3307
# Stop the container
$ docker-compose stop
# Destroy everything
$ docker-compose down
# Start the container
$ docker-compose start
Scaling is supported via docker-compose scale, however
conflicting options must be omitted:
hostname, ports, ipv4_address, volume
Docker Orchestration - Docker Swarm
Copyright 2012 Severalnines AB
● Multi-host deployment, through overlay network.
● Concepts:
○ Node
■ Manager - Dispatches tasks
■ Worker - Executes tasks by manager
○ Service
■ Replicated - Number of replicas
■ Global - One task per available node
○ Task
■ Container
○ Mesh routing
■ All Swarm nodes route to the running tasks
■ Ingress load balancing (round-robin only)
○ Scheduler
■ Resources availability
■ Label and constraints
Docker Orchestration - Simple Auto
Failover using Swarm
Copyright 2012 Severalnines AB
# Run a replica of MySQL service
$ docker service create 
--name mysql-service 
--replicas 1 
--net db_multi 
-p 3307:3306 
-e MYSQL_ROOT_PASSWORD=mypassword 
--mount
source=ebs-datadir,destination=/var/lib/mysql,volume-driv
er=rexray 
--mountsource=ebs-conf,destination=/etc/my.cnf.d,volume-d
river=rexray 
mysql:5.7
mysql-
service
Docker
Host 1
ebs-datadir
mysql-
service
Docker
Host 2
3307
ebs-conf
Docker Orchestration - Galera
Cluster on Swarm
Copyright 2012 Severalnines AB
# Bootstrap-only container
$ docker service create 
--name pxc-bs 
--replicas 1 
--net db-multi-hosts 
-e MYSQL_ROOT_PASSWORD=mypassword123 
-e CLUSTER_NAME=my_galera 
-e CLUSTER_JOIN= 
percona/percona-xtradb-cluster
Docker
Host 1
tasks.
pxc1
# 3-node Galera
$ for i in {1..3}; do docker service create 
--name pxc${i} 
--replicas 1 
--net db-multi-hosts 
-p 330${i}:3306 
-e MYSQL_ROOT_PASSWORD=mypassword123 
-e CLUSTER_NAME=my_galera 
-e CLUSTER_JOIN=tasks.pxc-bs,tasks.pxc1,tasks.pxc2,tasks.pxc3 
--mount source=pxc{i},target=/var/lib/mysql 
percona/percona-xtradb-cluster; 
sleep 1m; 
done
tasks.
pxc-b
s
# Remove bootstrap-only container
$ docker service rm pxc-bs
Docker
Host 2
tasks.
pxc2
Docker
Host 3
tasks.
pxc3
HAproxy
3301
3302
3303
3301
3302
3303
3301
3302
3303
3306
Docker Orchestration - Other
Orchestration Tools
Copyright 2012 Severalnines AB
Docker Orchestration - Best Practice for
MySQL
Copyright 2012 Severalnines AB
● Add label to node and use placement constraints:
○ Avoid overcommit resources.
○ Manageability and predictability.
● Use Service's name and virtual IP address to distinguish
container's role.
● Understand the scheduling strategy:
○ Spread
○ Binpack
○ Random
○ Custom
● Rolling update:
○ Only perform update one container at a time.
○ Add delay before move to the next container.
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
ClusterControl on Docker
ClusterControl on Docker - Image
Copyright 2012 Severalnines AB
● Image is available at Docker Hub. Dockerfile at Github.
● Automation software for database clusters.
● Status: Non-production.
● The image consists of:
○ ClusterControl v1.4.2
○ Percona Server for MySQL
○ Apache + SSL
○ SSH key
● Key changes:
○ Some ClusterControl defaults are changed to
support Docker.
○ Automatic deployment (Galera only)
# Create a user-defined bridge for DB network
$ docker network create --subnet=192.168.10.0/24
db-cluster
# Run a ClusterControl container
$ docker run -d --name clustercontrol 
--network db-cluster 
--ip 192.168.10.10 
-h clustercontrol 
-p 5000:80 
-p 5001:443 
-v /storage/clustercontrol/cmon.d:/etc/cmon.d 
-v /storage/clustercontrol/datadir:/var/lib/mysql 
-v /storage/clustercontrol/.ssh:/root/.ssh 
-v /storage/clustercontrol/backups:/root/backups 
-e CMON_PASSWORD mysecr3t 
-e MYSQL_ROOT_PASSWORD mys3cret 
severalnines/clustercontrol
# Restart cmon service inside container
$ docker exec -it clustercontrol supervisorctl
restart cmon
ClusterControl on Docker - Run as
Container
Copyright 2012 Severalnines AB
● Recommended volumes for data persistence:
○ /etc/cmon.d
○ /var/lib/mysql
○ /root/.ssh
○ /root/backups
● ClusterControl UI is exposed at 80 and 443 by default.
● Service control via supervisord: sshd, mysqld, httpd,
cmon, cmon-ssh, cmon-events, cc-auto-deployment
● Run it as:
○ --net=host, if you want this container to
manage host or container outside of Docker
network.
○ --net={net_name}, if you want CC container to
manage containers in the same Docker network.
# Run a ClusterControl container
$ docker run -d --name=clustercontrol 
-p 5000:80 
-p 5001:443 
-h clustercontrol 
-v /storage/clustercontrol/.ssh:/root/.ssh 
-v /storage/clustercontrol/datadir:/var/lib/mysql 
-v /storage/clustercontrol/cmon.d:/etc/cmon.d 
-v /storage/clustercontrol/backups:/backups 
severalnines/clustercontrol
# Run a 3 node Galera cluster, with auto deployment
$ for i in {1..3}; do
docker run -d 
--name galera${i} 
-p 666{$i}:3306 
--link clustercontrol:clustercontrol 
-e CLUSTER_TYPE=galera 
-e CLUSTER_NAME=mygalera 
-e INITIAL_CLUSTER_SIZE=3 
severalnines/centos-ssh
done
ClusterControl on Docker - Auto DB
Cluster Deployment
Copyright 2012 Severalnines AB
● Use "severalnines/centos-ssh" image - configures
passwordless SSH automatically from CC to DB
containers and register the container with CC.
● Only Galera is supported (more to come).
● Background script, cc-auto-deployment:
○ Monitors new containers registration.
○ Triggers deployment job if AUTO_DEPLOYMENT=1
(default).
○ Uses ClusterControl CLI, called 's9s' to interact
with cmon backend.
● Deployment flow:
○ You create the container.
○ cc-auto-deployment picks up the registered
containers and creates a deployment job.
○ ClusterControl deploys the cluster.
ClusterControl on Docker - Manual DB
Cluster Deployment
● Use "severalnines/centos-ssh" image with
AUTO_DEPLOYMENT=0.
● Allows user to have better control on the deployment
process initiates by ClusterControl.
● All supported database cluster can be deployed using
this method.
● Deployment flow:
a. You create the containers.
b. You create the database deployment job
through ClusterControl UI.
c. ClusterControl deploys the cluster.
Copyright 2012 Severalnines AB
Further Reading - Example at Github:
https://github.com/severalnines/docker/tree/master/examples/do
cker
ClusterControl on Docker - Add Existing
DB Containers
Copyright 2012 Severalnines AB
● Must be in the same Docker network with the DB
containers.
● SSH server and client must be installed and started on
the DB containers:
○ Setup passwordless SSH from ClusterControl
container to the DB containers.
○ It's going to improve though.
Further Reading - Import Existing DB Containers into
ClusterControl:
https://severalnines.com/blog/clustercontrol-docker
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
What's Next?
Copyright 2017 Severalnines AB
● Follow our MySQL on Docker blog series at
severalnines.com/blog
● Attend the 2nd MySQL on Docker webinar, MySQL
Container Management:
○ Coming Soon in November 2017
● Deploy DB containers using ClusterControl Docker
image.
What's Next

More Related Content

More from Severalnines

Webinar slides: Backup Management for MySQL, MariaDB, PostgreSQL & MongoDB wi...
Webinar slides: Backup Management for MySQL, MariaDB, PostgreSQL & MongoDB wi...Webinar slides: Backup Management for MySQL, MariaDB, PostgreSQL & MongoDB wi...
Webinar slides: Backup Management for MySQL, MariaDB, PostgreSQL & MongoDB wi...Severalnines
 
Disaster Recovery Planning for MySQL & MariaDB
Disaster Recovery Planning for MySQL & MariaDBDisaster Recovery Planning for MySQL & MariaDB
Disaster Recovery Planning for MySQL & MariaDBSeveralnines
 
MariaDB Performance Tuning Crash Course
MariaDB Performance Tuning Crash CourseMariaDB Performance Tuning Crash Course
MariaDB Performance Tuning Crash CourseSeveralnines
 
Performance Tuning Cheat Sheet for MongoDB
Performance Tuning Cheat Sheet for MongoDBPerformance Tuning Cheat Sheet for MongoDB
Performance Tuning Cheat Sheet for MongoDBSeveralnines
 
Advanced MySql Data-at-Rest Encryption in Percona Server
Advanced MySql Data-at-Rest Encryption in Percona ServerAdvanced MySql Data-at-Rest Encryption in Percona Server
Advanced MySql Data-at-Rest Encryption in Percona ServerSeveralnines
 
Polyglot Persistence Utilizing Open Source Databases as a Swiss Pocket Knife
Polyglot Persistence Utilizing Open Source Databases as a Swiss Pocket KnifePolyglot Persistence Utilizing Open Source Databases as a Swiss Pocket Knife
Polyglot Persistence Utilizing Open Source Databases as a Swiss Pocket KnifeSeveralnines
 
Webinar slides: Free Monitoring (on Steroids) for MySQL, MariaDB, PostgreSQL ...
Webinar slides: Free Monitoring (on Steroids) for MySQL, MariaDB, PostgreSQL ...Webinar slides: Free Monitoring (on Steroids) for MySQL, MariaDB, PostgreSQL ...
Webinar slides: Free Monitoring (on Steroids) for MySQL, MariaDB, PostgreSQL ...Severalnines
 
Webinar slides: An Introduction to Performance Monitoring for PostgreSQL
Webinar slides: An Introduction to Performance Monitoring for PostgreSQLWebinar slides: An Introduction to Performance Monitoring for PostgreSQL
Webinar slides: An Introduction to Performance Monitoring for PostgreSQLSeveralnines
 
Webinar slides: Our Guide to MySQL & MariaDB Performance Tuning
Webinar slides: Our Guide to MySQL & MariaDB Performance TuningWebinar slides: Our Guide to MySQL & MariaDB Performance Tuning
Webinar slides: Our Guide to MySQL & MariaDB Performance TuningSeveralnines
 
Webinar slides: Migrating to Galera Cluster for MySQL and MariaDB
Webinar slides: Migrating to Galera Cluster for MySQL and MariaDBWebinar slides: Migrating to Galera Cluster for MySQL and MariaDB
Webinar slides: Migrating to Galera Cluster for MySQL and MariaDBSeveralnines
 
Webinar slides: How to Measure Database Availability?
Webinar slides: How to Measure Database Availability?Webinar slides: How to Measure Database Availability?
Webinar slides: How to Measure Database Availability?Severalnines
 
Webinar slides: Designing Open Source Databases for High Availability
Webinar slides: Designing Open Source Databases for High AvailabilityWebinar slides: Designing Open Source Databases for High Availability
Webinar slides: Designing Open Source Databases for High AvailabilitySeveralnines
 
Webinar slides: How to Get Started with Open Source Database Management
Webinar slides: How to Get Started with Open Source Database ManagementWebinar slides: How to Get Started with Open Source Database Management
Webinar slides: How to Get Started with Open Source Database ManagementSeveralnines
 
Webinar slides: How to Achieve PCI Compliance for MySQL & MariaDB with Cluste...
Webinar slides: How to Achieve PCI Compliance for MySQL & MariaDB with Cluste...Webinar slides: How to Achieve PCI Compliance for MySQL & MariaDB with Cluste...
Webinar slides: How to Achieve PCI Compliance for MySQL & MariaDB with Cluste...Severalnines
 
Webinar slides: Severalnines & MariaDB present: Automation & Management of Ma...
Webinar slides: Severalnines & MariaDB present: Automation & Management of Ma...Webinar slides: Severalnines & MariaDB present: Automation & Management of Ma...
Webinar slides: Severalnines & MariaDB present: Automation & Management of Ma...Severalnines
 
Webinar slides: How to automate and manage MongoDB & Percona Server for MongoDB
Webinar slides: How to automate and manage MongoDB & Percona Server for MongoDBWebinar slides: How to automate and manage MongoDB & Percona Server for MongoDB
Webinar slides: How to automate and manage MongoDB & Percona Server for MongoDBSeveralnines
 
MySQL on Docker - Containerizing the Dolphin
MySQL on Docker - Containerizing the DolphinMySQL on Docker - Containerizing the Dolphin
MySQL on Docker - Containerizing the DolphinSeveralnines
 
Automating and Managing MongoDB: An Analysis of Ops Manager vs. ClusterControl
Automating and Managing MongoDB: An Analysis of Ops Manager vs. ClusterControlAutomating and Managing MongoDB: An Analysis of Ops Manager vs. ClusterControl
Automating and Managing MongoDB: An Analysis of Ops Manager vs. ClusterControlSeveralnines
 
MySQL Load Balancers - MaxScale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
MySQL Load Balancers - MaxScale, ProxySQL, HAProxy, MySQL Router & nginx - A ...MySQL Load Balancers - MaxScale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
MySQL Load Balancers - MaxScale, ProxySQL, HAProxy, MySQL Router & nginx - A ...Severalnines
 
Webinar slides: DevOps Tutorial: how to automate your database infrastructure
Webinar slides: DevOps Tutorial: how to automate your database infrastructureWebinar slides: DevOps Tutorial: how to automate your database infrastructure
Webinar slides: DevOps Tutorial: how to automate your database infrastructureSeveralnines
 

More from Severalnines (20)

Webinar slides: Backup Management for MySQL, MariaDB, PostgreSQL & MongoDB wi...
Webinar slides: Backup Management for MySQL, MariaDB, PostgreSQL & MongoDB wi...Webinar slides: Backup Management for MySQL, MariaDB, PostgreSQL & MongoDB wi...
Webinar slides: Backup Management for MySQL, MariaDB, PostgreSQL & MongoDB wi...
 
Disaster Recovery Planning for MySQL & MariaDB
Disaster Recovery Planning for MySQL & MariaDBDisaster Recovery Planning for MySQL & MariaDB
Disaster Recovery Planning for MySQL & MariaDB
 
MariaDB Performance Tuning Crash Course
MariaDB Performance Tuning Crash CourseMariaDB Performance Tuning Crash Course
MariaDB Performance Tuning Crash Course
 
Performance Tuning Cheat Sheet for MongoDB
Performance Tuning Cheat Sheet for MongoDBPerformance Tuning Cheat Sheet for MongoDB
Performance Tuning Cheat Sheet for MongoDB
 
Advanced MySql Data-at-Rest Encryption in Percona Server
Advanced MySql Data-at-Rest Encryption in Percona ServerAdvanced MySql Data-at-Rest Encryption in Percona Server
Advanced MySql Data-at-Rest Encryption in Percona Server
 
Polyglot Persistence Utilizing Open Source Databases as a Swiss Pocket Knife
Polyglot Persistence Utilizing Open Source Databases as a Swiss Pocket KnifePolyglot Persistence Utilizing Open Source Databases as a Swiss Pocket Knife
Polyglot Persistence Utilizing Open Source Databases as a Swiss Pocket Knife
 
Webinar slides: Free Monitoring (on Steroids) for MySQL, MariaDB, PostgreSQL ...
Webinar slides: Free Monitoring (on Steroids) for MySQL, MariaDB, PostgreSQL ...Webinar slides: Free Monitoring (on Steroids) for MySQL, MariaDB, PostgreSQL ...
Webinar slides: Free Monitoring (on Steroids) for MySQL, MariaDB, PostgreSQL ...
 
Webinar slides: An Introduction to Performance Monitoring for PostgreSQL
Webinar slides: An Introduction to Performance Monitoring for PostgreSQLWebinar slides: An Introduction to Performance Monitoring for PostgreSQL
Webinar slides: An Introduction to Performance Monitoring for PostgreSQL
 
Webinar slides: Our Guide to MySQL & MariaDB Performance Tuning
Webinar slides: Our Guide to MySQL & MariaDB Performance TuningWebinar slides: Our Guide to MySQL & MariaDB Performance Tuning
Webinar slides: Our Guide to MySQL & MariaDB Performance Tuning
 
Webinar slides: Migrating to Galera Cluster for MySQL and MariaDB
Webinar slides: Migrating to Galera Cluster for MySQL and MariaDBWebinar slides: Migrating to Galera Cluster for MySQL and MariaDB
Webinar slides: Migrating to Galera Cluster for MySQL and MariaDB
 
Webinar slides: How to Measure Database Availability?
Webinar slides: How to Measure Database Availability?Webinar slides: How to Measure Database Availability?
Webinar slides: How to Measure Database Availability?
 
Webinar slides: Designing Open Source Databases for High Availability
Webinar slides: Designing Open Source Databases for High AvailabilityWebinar slides: Designing Open Source Databases for High Availability
Webinar slides: Designing Open Source Databases for High Availability
 
Webinar slides: How to Get Started with Open Source Database Management
Webinar slides: How to Get Started with Open Source Database ManagementWebinar slides: How to Get Started with Open Source Database Management
Webinar slides: How to Get Started with Open Source Database Management
 
Webinar slides: How to Achieve PCI Compliance for MySQL & MariaDB with Cluste...
Webinar slides: How to Achieve PCI Compliance for MySQL & MariaDB with Cluste...Webinar slides: How to Achieve PCI Compliance for MySQL & MariaDB with Cluste...
Webinar slides: How to Achieve PCI Compliance for MySQL & MariaDB with Cluste...
 
Webinar slides: Severalnines & MariaDB present: Automation & Management of Ma...
Webinar slides: Severalnines & MariaDB present: Automation & Management of Ma...Webinar slides: Severalnines & MariaDB present: Automation & Management of Ma...
Webinar slides: Severalnines & MariaDB present: Automation & Management of Ma...
 
Webinar slides: How to automate and manage MongoDB & Percona Server for MongoDB
Webinar slides: How to automate and manage MongoDB & Percona Server for MongoDBWebinar slides: How to automate and manage MongoDB & Percona Server for MongoDB
Webinar slides: How to automate and manage MongoDB & Percona Server for MongoDB
 
MySQL on Docker - Containerizing the Dolphin
MySQL on Docker - Containerizing the DolphinMySQL on Docker - Containerizing the Dolphin
MySQL on Docker - Containerizing the Dolphin
 
Automating and Managing MongoDB: An Analysis of Ops Manager vs. ClusterControl
Automating and Managing MongoDB: An Analysis of Ops Manager vs. ClusterControlAutomating and Managing MongoDB: An Analysis of Ops Manager vs. ClusterControl
Automating and Managing MongoDB: An Analysis of Ops Manager vs. ClusterControl
 
MySQL Load Balancers - MaxScale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
MySQL Load Balancers - MaxScale, ProxySQL, HAProxy, MySQL Router & nginx - A ...MySQL Load Balancers - MaxScale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
MySQL Load Balancers - MaxScale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
 
Webinar slides: DevOps Tutorial: how to automate your database infrastructure
Webinar slides: DevOps Tutorial: how to automate your database infrastructureWebinar slides: DevOps Tutorial: how to automate your database infrastructure
Webinar slides: DevOps Tutorial: how to automate your database infrastructure
 

Recently uploaded

Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Sheetaleventcompany
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Delhi Call girls
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...APNIC
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.soniya singh
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445ruhi
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...Escorts Call Girls
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...singhpriety023
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceDelhi Call girls
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...tanu pandey
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.soniya singh
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Servicegwenoracqe6
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
 
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$kojalkojal131
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Standkumarajju5765
 

Recently uploaded (20)

Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
 
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
 

Webinar slides: MySQL on Docker: Understanding the Basics

  • 1. Copyright 2017 Severalnines AB I'm Jean-Jérôme from the Severalnines Team and I'm your host for today's webinar! Feel free to ask any questions in the Questions section of this application or via the Chat box. You can also contact me directly via the chat box or via email: info@severalnines.com during or after the webinar. Your host & some logistics
  • 2. Copyright 2017 Severalnines AB Copyright 2017 Severalnines AB About Severalnines and ClusterControl
  • 4. Copyright 2017 Severalnines AB ClusterControl Automation & Management Management ● Multi-Cluster / Multi-DC ● Automate Repair & Recovery ● Database Upgrades ● Backups ● Configuration Management ● Database Cloning ● One-Click Scaling Deployment ● Deploy a Cluster in Minutes ● On-Premises or in the Cloud (AWS) Monitoring ● Systems View with 1sec Resolution ● DB / OS stats & Performance Advisors ● Configurable Dashboards ● Query Analyzer ● Real-time / historical
  • 5. Copyright 2017 Severalnines AB Supported Databases
  • 6. Copyright 2012 Severalnines ABCopyright 2012 Severalnines AB Our Customers
  • 7. Sep 2017 MySQL on Docker: Understanding the Basics Ashraf Sharif, Support Engineer Presenter ashraf@severalnines.com
  • 8. Agenda Copyright 2012 Severalnines AB ● Introduction ● Image ● Container ● Volume ● Network ● Orchestration ● ClusterControl on Docker ● Q&A
  • 9. Copyright 2017 Severalnines AB Copyright 2017 Severalnines AB Introduction
  • 10. What is Docker? Copyright 2012 Severalnines AB ● Lightweight application container platform. ● Each container has its own: ○ Filesystem ○ Process space ○ Network stack ● Use pre-built image. ● Advantages: ○ Rapid deployment ○ Greater density per host ○ Isolation Docker Architecture
  • 11. Docker Components Copyright 2012 Severalnines AB Docker Components
  • 12. Copyright 2017 Severalnines AB Copyright 2017 Severalnines AB Docker Image
  • 13. Docker Image - Introduction Copyright 2012 Severalnines AB ● A template for Docker container. ● Create an image: ○ Commit the container's changes ○ Build from Dockerfile ● Share the image: ○ Save as tarball. ○ Push to registry: ■ Public - Docker Hub, Docker Store ■ Private, hosted - Quay, ECR, GCR, Bintray, Artifactory ■ Private, self-hosted - Your own registry # Save image to tarball $ docker save -o mysql.tar abc # Start your own Docker registry service $ docker run -d -p 5000:5000 --name registry registry:2 # Push image to Docker Hub $ docker push myimage/mysql:5.7
  • 14. Docker Image - Commit a Container Copyright 2012 Severalnines AB Host # Save image to tarball $ docker run -d --name=abc ubuntu:16.04 # Commit the changes (in another window) $ docker commit abc myimage/mysql:5.7 # Push image to Docker Hub $ docker exec -it abc /bin/bash root@abc:/# apt-get update root@abc:/# DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server root@abc:/# vi /etc/mysql/my.cnf # Ubuntu 16.04 host $ apt-get update $ DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server $ vi /etc/mysql/my.cnf # Run MySQL server as a process $ mysqld --socket=/var/lib/mysql/mysqld.sock --pid-file=/var/lib/mysql/mysqld.pid Docker # Run MySQL server as a container $ docker run -d myimage/mysql:5.7 mysqld --socket=/var/lib/mysql/mysqld.sock --pid-file=/var/lib/mysql/mysqld.pid
  • 15. Docker Image - Using Dockerfile Copyright 2012 Severalnines AB Host # Build as image $ docker build -t myimage/mysql:5.7 . # vi Dockerfile FROM ubuntu:16.04 RUN apt-get update RUN DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server COPY my.cnf /etc/mysql/my.cnf EXPOSE 3306 # Ubuntu 16.04 host $ apt-get update $ DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server $ vi /etc/mysql/my.cnf # Run MySQL server as a process $ mysqld --socket=/var/lib/mysql/mysqld.sock --pid-file=/var/lib/mysql/mysqld.pid Docker # Run MySQL server as a container $ docker run -d myimage/mysql:5.7 mysqld --socket=/var/lib/mysql/mysqld.sock --pid-file=/var/lib/mysql/mysqld.pid # Create MySQL config file $ vi my.cnf
  • 16. Docker Image - Build an Image Copyright 2012 Severalnines AB # Get image size $ docker images REPOSITORY TAG SIZE myimage/mysql 5.7 529MB # Show created layers $ docker history myimage/mysql:5.7 CREATED BY SIZE /bin/sh -c #(nop) COPY file:e8163ef656b6da... 101B /bin/sh -c DEBIAN_FRONTEND=noninteractive ... 370MB /bin/sh -c apt-get update 39.1MB /bin/sh -c #(nop) CMD ["/bin/bash"] 0B /bin/sh -c mkdir -p /run/systemd && echo '... 7B /bin/sh -c sed -i 's/^#s*(deb.*universe... 2.76kB /bin/sh -c rm -rf /var/lib/apt/lists/* 0B /bin/sh -c set -xe && echo '#!/bin/sh' >... 745B /bin/sh -c #(nop) ADD file:39d3593ea220e68... 120MB de70fa77eb2b f6016aab25f1 0639788facc8 35369f9634e1 937bbdd4305a 724179e94999 f6016aab25f1 d51f459239fb Image: myimage/mysql:5.7 ubuntu:16.04 ad74af05f5a2 Dockerfile
  • 17. Docker Image - Best Practice for MySQL Copyright 2012 Severalnines AB # Get image size $ docker images REPOSITORY TAG SIZE mysql 5.6 299MB mysql 5.7 412MB # tail entrypoint.sh ... ... exec mysqld "$@" ● Extend an existing image available in the registry, instead of building a new one from scratch. ● The smaller the image size, the faster the deployment. (Hint: alpine). ● If using an entrypoint script, ensure mysqld command runs with "exec", indicating it's the primary process that holds PID 1 inside container. ● General guidelines: https://docs.docker.com/engine/userguide/eng-image/ dockerfile_best-practices/ # vi Dockerfile FROM mysql:5.7 # vi Dockerfile FROM ubuntu:16.04 RUN apt-get install {all MySQL stuff}
  • 18. Copyright 2017 Severalnines AB Copyright 2017 Severalnines AB Docker Container
  • 19. Docker Container - Run a Single Container Copyright 2012 Severalnines AB # Run a MySQL container $ docker run -d --name my-test --env MYSQL_ROOT_PASSWORD=mypassword mysql # Get the container layer size $ docker ps -s CONTAINER ID IMAGE NAMES SIZE d51f459239fb mysql my-test 4B (virtual 412MB) Image: docker.io/mysql:latest de70fa77eb2b f6016aab25f1 0639788facc8 35369f9634e1 937bbdd4305a ad74af05f5a2 d51f459239fb 0639788facc8 35369f9634e1 937bbdd4305a my-test Image layers (RO) 412 MB Container layers (RW) 4 B
  • 20. Docker Container - Run another Container Copyright 2012 Severalnines AB # Run a MySQL container $ docker run -d --name my-test2 --env MYSQL_ROOT_PASSWORD=mypassword mysql # Get the container layer size $ docker ps -s CONTAINER ID IMAGE NAMES SIZE d51f459239fb mysql my-test 4B (virtual 412MB) e9de9ed50ced mysql my-test2 4B (virtual 412MB) Image: docker.io/mysql de70fa77eb2b f6016aab25f1 0639788facc8 35369f9634e1 937bbdd4305a ad74af05f5a2 d51f459239fb 0639788facc8 35369f9634e1 937bbdd4305a my-test Image layers (RO) 412 MB Container layers (RW) 4 B + 4 B e9de9ed50ced my-test2
  • 21. Docker Container - Container Layer Changes Copyright 2012 Severalnines AB # Operation 2 - Create a schema and table $ docker exec -it my-test mysql -uroot -pmypassword -e 'CREATE SCHEMA testdb; CREATE TABLE t1 (id INT PRIMARY KEY AUTO_INCREMENT, data TEXT);' Image: docker.io/mysql de70fa77eb2b f6016aab25f1 0639788facc8 35369f9634e1 937bbdd4305a ad74af05f5a2 d51f459239fb 0639788facc8 35369f9634e1 937bbdd4305a my-test c33a2b88395d Copy-on-Write (CoW) 416f2a97355f Supported CoW file system & devices: AUFS, Btrfs, Device Mapper, OverlayFS/Overlay2, ZFS, VFS # Operation 1 - Update /etc/mysql/my.cnf $ docker exec -it my-test vi /etc/mysql/my.cnf 1 2New Branch
  • 22. Docker Container - Application vs Data Copyright 2012 Severalnines AB Application Data Stateless Stateful Ephemeral Persistent Independant Dependant Frontend Backend Web, API Database, File Storage
  • 23. Copyright 2017 Severalnines AB Copyright 2017 Severalnines AB Docker Volume
  • 24. Docker Volume - Type Copyright 2012 Severalnines AB # Mount a named volume into container -v mysql1-data:/var/lib/mysql # Mount tmpfs into container --tmpfs /tmp ● Bind mount: ○ A file or directory on the host machine is mounted into a container. ○ You manage the directory’s contents. ● Named volume: ○ A new directory is created within Docker’s storage directory. ○ Docker manages the directory’s contents. ○ Extensible via volume plugin. ● tmpfs: ○ Stored on host machine’s memory (or swap). ○ Linux only. # Bind mount a directory into container -v /data/mysql1/data:/var/lib/mysql # Bind mount a file into container -v /data/mysql1/my.cnf:/etc/mysql/my.cnf
  • 25. Docker Volume - Persistent Volumes Copyright 2012 Severalnines AB # Run with persistent named volume, using -v or --volume $ docker run -d --name mysql-local --env MYSQL_ROOT_PASSWORD=mypassword --volume local-datadir:/var/lib/mysql mysql:5.7 Image: docker.io/mysql:5.7 de70fa77eb2b f6016aab25f1 0639788facc8 35369f9634e1 937bbdd4305a ad74af05f5a2 0639788facc8 35369f9634e1 937bbdd4305a mysql-local 416f2a92355f /var/lib/mysql local-datadir # Run with persistent named volume, using --mount $ docker run -d --name mysql-local --env MYSQL_ROOT_PASSWORD=mypassword --mount source=local-datadir,target=/var/lib/mysql mysql:5.7
  • 26. Docker Volume - Changes on Volume Copyright 2012 Severalnines AB # Run a container with port 3308 $ docker run -d --name mysql-local -p 3308:3306 -e MYSQL_ROOT_PASSWORD=mypassword -v local-datadir:/var/lib/mysql mysql Image: docker.io/mysql:latest de70fa77eb2b f6016aab25f1 0639788facc8 35369f9634e1 937bbdd4305a ad74af05f5a2 0639788facc8 35369f9634e1 937bbdd4305a mysql-local 416f2a92355f /var/lib/mysql local-datadir # Run with persistent named volume, using --mount $ mysql -uroot -p -h127.0.0.1 -P3308 < dump.sql dump .sql 3308
  • 27. Docker Volume - Remote Volume Copyright 2012 Severalnines AB # Run a container with NFS bind mount $ docker run -d --name mysql-nfs -p 3308:3306 -e MYSQL_ROOT_PASSWORD=mypassword -v /nfs/mysql-nfs:/var/lib/mysql mysql Image: docker.io/mysql de70fa77eb2b f6016aab25f1 0639788facc8 35369f9634e1 937bbdd4305a ad74af05f5a2 0639788facc8 35369f9634e1 937bbdd4305a mysql-nfs 416f2a92355f /var/lib/mysql 192.168.1.100 /storage/docker # Mount NFS with extra options for MySQL $ mount 192.168.1.100:/storage/docker /nfs -o noatime,nodiratime,hard,intr 3308 /nfs/mysql-nfs Further Reading - Using NFS with MySQL: https://dev.mysql.com/doc/refman/5.7/en/disk-issues.htm l#disk-issues-nfs
  • 28. Docker Volume - MySQL Persistency Copyright 2012 Severalnines AB Description Variable Name Default Value (5.7) MySQL data directory datadir /var/lib/mysql MySQL plugin directory plugin_dir {basedir}/lib/plugin MySQL configuration directory config_dir /etc/my.cnf.d MySQL binary log log_bin {datadir}/{hostname}-bin Slow query log slow_query_log_file {datadir}/{hostname}-slow.log Error log log_error {datadir}/{hostname}.err General log general_log_file {datadir}/{hostname}.log
  • 29. Docker Volume - Non-Persistent Volume Copyright 2012 Severalnines AB # Run a container with NFS bind mount and tmpfs volumes $ docker run -d --name mysql-nfs-tmp -p 3308:3306 -e MYSQL_ROOT_PASSWORD=mypassword -v /nfs/mysql-nfs:/var/lib/mysql --tmpfs /tmp:rw,size=1g,mode=177 mysql Image: docker.io/mysql:latest de70fa77eb2b f6016aab25f1 0639788facc8 35369f9634e1 937bbdd4305a ad74af05f5a2 0639788facc8 35369f9634e1 937bbdd4305a mysql-nfs-tmp 416f2a92355f /var/lib/mysql 192.168.1.100 /storage/docker 3308 /nfs/mysql-nfs /tmp
  • 30. Docker Volume - Drivers Copyright 2012 Severalnines AB ● Default is local. ● You can use other different volume driver (or plugin). ○ Install the plugin. ○ Use --volume-driver option. ● Volume drivers allow you to extend Docker's volume capabilities: ○ Snapshot ○ Backup ○ Encryption # Install Rexray EBS docker plugin $ docker plugin install rexray/ebs EBS_ACCESSKEY=XXXX EBS_SECRETKEY=YYYY # Verify if the plugin is loaded $ docker info -f '{{json .Plugins.Volume}}' | jq [ "local", "rexray" ] # Run a container with volume plugin $ docker run -d --name=mysql-ebs --volume-driver=rexray/ebs -v ebs-datadir:/var/lib/mysql mysql:5.7 # List volumes $ docker volume ls DRIVER VOLUME NAME local local-datadir1 local local-datadir2 rexray ebs-datadir
  • 31. Docker Volume - Drivers and Storage Platforms Copyright 2012 Severalnines AB Further Reading - Volume Plugins List: https://docs.docker.com/engine/extend/legacy_plugins/#volume-plugins Contiv Fuxi Netshare REX-ray Horcrux Convoy OpenStorage Amazon S3 Azure FS Google PD Amazon EBS DigitalOcean BS Flocker EMC FUSE vSphere iSCSI CIFS NetApp OpenStack Cinder Minio CephFS BeeGFS NFS SMB Infinit
  • 32. Docker Volume - Simple Benchmark Copyright 2012 Severalnines AB Local vs NFS vs NFS-tweaked vs EBS-standard
  • 33. Copyright 2017 Severalnines AB Copyright 2017 Severalnines AB Docker Network
  • 34. Docker Network - Types Copyright 2012 Severalnines AB ● Single-host: ○ Host ○ None ○ Bridge ■ Default bridge (docker0) ■ User-defined bridge ● Multi-host: ○ Default overlay ○ User-defined overlay ● Extensible via Docker network plugins. # List all networks $ docker network ls NAME DRIVER SCOPE bridge bridge local db_multi overlay swarm db_single bridge local docker_gwbridge bridge local host host local ingress overlay swarm none null local
  • 35. Docker Network - Host Network Copyright 2012 Severalnines AB # Run a container on host network $ docker run -d --name mysql-host --net host -e MYSQL_ROOT_PASSWORD=mypassword mysql:5.7 Container 1 eth0 eth0 Container 2 eth0 Docker Host # Display active TCP connections $ netstat -tulpn | grep mysql tcp6 0 0 :::3306 :::* LISTEN 24601/mysqld ● Container’s network interfaces will be identical with the machine host. ● Only one host network per machine host. ● Container linking, --link mysql-test:mysql is not supported. ● Port mapping, --publish 3307:3306 is not supported.
  • 36. Docker Network - Default Bridge Network Copyright 2012 Severalnines AB # Run a container on docker0 bridge network $ docker run -d --name mysql-bridge -p 3308:3306 -e MYSQL_ROOT_PASSWORD=mypassword mysql:5.7 Container 1 eth0 eth0 Container 2 eth0 Docker Host # Display active TCP connections $ netstat -tulpn | grep 3308 tcp6 0 0 :::3308 :::* LISTEN 24601/docker-proxy ● Packet forwarding by iptables to the bridge network. ● --publish is supported. Run multiple containers with same image through different ports. ● --link is supported. Link with other containers to expose environment variables. ● docker-proxy redirects connection to the correct container through NAT. docker0 (virtual Ethernet bridge) vethxxx vethyyy
  • 37. Docker Network - User-Defined Bridge Network Copyright 2012 Severalnines AB # Run a container on user bridge network $ docker run -d --name mysql1 --net db_single -p 3308:3306 --ip 192.168.10.10 --hostname mysql1 -e MYSQL_ROOT_PASSWORD=mypassword mysql:5.7 Container 1 eth0 eth0 Container 2 eth0 Docker Host # Create a new bridge network $ docker network create subnet=192.168.10.0/24 db_single Similar to the default docker0 bridge, plus: ● --hostname is supported for sticky hostname. ● --ip is supported for sticky IP address. ● --link is not supported. Use embedded DNS to resolve container's name in the same network. db_single (virtual Ethernet bridge) vethxxx vethyyy DNS
  • 38. Docker Network - Plugins Copyright 2012 Severalnines AB ● Similar to volume, Docker network can be extended through plugins: ○ Multi-host networking (must use outside of Swarm) ○ Name resolver and service discovery. ○ Encryption. ● Popular network plugins: ○ Contiv ○ Calico ○ Weave ○ Flannel Further Reading - Multi-host Networking with Calico: https://severalnines.com/blog/mysql-docker-multi-host-networkin g-mysql-containers-part-2-calico
  • 39. Docker Network - Default Overlay Network Copyright 2012 Severalnines AB # Run a service on default overlay network $ docker service create --name mysql-service --replicas 1 -p 3308:3306 -e MYSQL_ROOT_PASSWORD=mypassword -v nfs-datadir:/var/lib/mysql mysql:5.7 Container 1 eth0 eth0 eth1 Docker Host # Initialize Docker Swarm $ docker swarm init ● Docker Swarm must be enabled. ● Each task (container) has: ○ eth0 - Interface to external network via docker_gwbridge. ○ eth1 - Interface to overlay network via VXLAN. docker_gw bridge vethxxx vethyyy br0 External Container 2 eth0 eth1 Docker docker_gw bridge vethxxx vethyyy br0 eth0 Host VXLAN udp/4789
  • 40. Docker Network - User-Defined Overlay Network Copyright 2012 Severalnines AB # Run a service on default overlay network $ docker service create --name mysql-service --replicas 1 --net db_multi -p 3308:3306 -e MYSQL_ROOT_PASSWORD=mypassword -v nfs-datadir:/var/lib/mysql mysql:5.7 Container 1 eth0 eth0 eth1 Docker Host # Create an overlay network $ docker network create -d overlay db_multi Similar with the default overlay, plus: ● Embedded DNS resolver: ○ {service_name} → Service VIP ○ tasks.{service_name} → Container's IP docker_gw bridge vethxxx vethyyy br0 External Container 2 eth0 eth1 Docker docker_gw bridge vethxxx vethyyy br0 eth0 Host VXLAN udp/4789 DNS
  • 41. Copyright 2017 Severalnines AB Copyright 2017 Severalnines AB Docker Orchestration
  • 42. Docker Orchestration - Container Orchestration Copyright 2012 Severalnines AB ● Simplify container's management at scale. ● Concept: ○ Multiple containers as one entity. ○ Structural YAML formatting. ● Official Docker comes with: ○ Docker Compose: ■ single-host, small scale, separate package. ○ Docker Swarm: ■ multi-host, big scale, out-of-the-box. ■ support compose formatting through docker stack.
  • 43. Docker Orchestration - Docker Compose Copyright 2012 Severalnines AB Docker CLI version: '2' services: mysql-prod: image: mysql:5.7.16 command: - --innodb_buffer_pool_size=2G - --max_connections=50 ports: - "3307:3306" environment: MYSQL_ROOT_PASSWORD: r00tP4ssw0rD MYSQL_USER: myshop MYSQL_PASSWORD: MyS3creTP4s5 MYSQL_DATABASE: myshop hostname: mysql-prod networks: db-prod: ipv4_address: 192.168.10.101 volumes: - mysql-datadir:/var/lib/mysql - mysql-tmp:/tmp ulimits: nofile: soft: 16824 hard: 16824 mem_limit: 4g memswap_limit: 4g volumes: mysql-datadir: mysql-tmp: networks: db-prod: driver: bridge ipam: driver: default config: - subnet: 192.168.10.0/24 # Production MySQL container - full command $ docker network create --subnet=192.168.10.0/24 db-prod $ docker run -d --name mysql-prod --net db-production --publish 3307:3306 --ip 192.168.10.101 --hostname mysql-prod --memory 4g --memory-swap 4g --ulimit nofile=16824:16824 --volume mysql-datadir:/var/lib/mysql --volume mysql-tmp:/tmp --env MYSQL_ROOT_PASSWORD=r00tP4ssw0rD --env MYSQL_USER=myshop --env MYSQL_PASSWORD=MyS3creTP4s5 --env MYSQL_DATABASE=myshop mysql:5.7.16 --innodb_buffer_pool_size=2G --max_connections=50
  • 44. Docker Orchestration - Run with Docker Compose Copyright 2012 Severalnines AB # Bring up the production MySQL container in background $ docker-compose up -d Creating network "compose_db-prod" with driver "bridge" Creating compose_mysql-prod_1 Image: docker.io/mysql:5.7.18 de70fa77eb2b f6016aab25f1 0639788facc8 35369f9634e1 937bbdd4305a ad74af05f5a2 0639788facc8 35369f9634e1 937bbdd4305a mysql-prod 416f2a92355f /var/lib/mysql mysql-datadir /tmp mysql-tmp 3307 # Stop the container $ docker-compose stop # Destroy everything $ docker-compose down # Start the container $ docker-compose start Scaling is supported via docker-compose scale, however conflicting options must be omitted: hostname, ports, ipv4_address, volume
  • 45. Docker Orchestration - Docker Swarm Copyright 2012 Severalnines AB ● Multi-host deployment, through overlay network. ● Concepts: ○ Node ■ Manager - Dispatches tasks ■ Worker - Executes tasks by manager ○ Service ■ Replicated - Number of replicas ■ Global - One task per available node ○ Task ■ Container ○ Mesh routing ■ All Swarm nodes route to the running tasks ■ Ingress load balancing (round-robin only) ○ Scheduler ■ Resources availability ■ Label and constraints
  • 46. Docker Orchestration - Simple Auto Failover using Swarm Copyright 2012 Severalnines AB # Run a replica of MySQL service $ docker service create --name mysql-service --replicas 1 --net db_multi -p 3307:3306 -e MYSQL_ROOT_PASSWORD=mypassword --mount source=ebs-datadir,destination=/var/lib/mysql,volume-driv er=rexray --mountsource=ebs-conf,destination=/etc/my.cnf.d,volume-d river=rexray mysql:5.7 mysql- service Docker Host 1 ebs-datadir mysql- service Docker Host 2 3307 ebs-conf
  • 47. Docker Orchestration - Galera Cluster on Swarm Copyright 2012 Severalnines AB # Bootstrap-only container $ docker service create --name pxc-bs --replicas 1 --net db-multi-hosts -e MYSQL_ROOT_PASSWORD=mypassword123 -e CLUSTER_NAME=my_galera -e CLUSTER_JOIN= percona/percona-xtradb-cluster Docker Host 1 tasks. pxc1 # 3-node Galera $ for i in {1..3}; do docker service create --name pxc${i} --replicas 1 --net db-multi-hosts -p 330${i}:3306 -e MYSQL_ROOT_PASSWORD=mypassword123 -e CLUSTER_NAME=my_galera -e CLUSTER_JOIN=tasks.pxc-bs,tasks.pxc1,tasks.pxc2,tasks.pxc3 --mount source=pxc{i},target=/var/lib/mysql percona/percona-xtradb-cluster; sleep 1m; done tasks. pxc-b s # Remove bootstrap-only container $ docker service rm pxc-bs Docker Host 2 tasks. pxc2 Docker Host 3 tasks. pxc3 HAproxy 3301 3302 3303 3301 3302 3303 3301 3302 3303 3306
  • 48. Docker Orchestration - Other Orchestration Tools Copyright 2012 Severalnines AB
  • 49. Docker Orchestration - Best Practice for MySQL Copyright 2012 Severalnines AB ● Add label to node and use placement constraints: ○ Avoid overcommit resources. ○ Manageability and predictability. ● Use Service's name and virtual IP address to distinguish container's role. ● Understand the scheduling strategy: ○ Spread ○ Binpack ○ Random ○ Custom ● Rolling update: ○ Only perform update one container at a time. ○ Add delay before move to the next container.
  • 50. Copyright 2017 Severalnines AB Copyright 2017 Severalnines AB ClusterControl on Docker
  • 51. ClusterControl on Docker - Image Copyright 2012 Severalnines AB ● Image is available at Docker Hub. Dockerfile at Github. ● Automation software for database clusters. ● Status: Non-production. ● The image consists of: ○ ClusterControl v1.4.2 ○ Percona Server for MySQL ○ Apache + SSL ○ SSH key ● Key changes: ○ Some ClusterControl defaults are changed to support Docker. ○ Automatic deployment (Galera only)
  • 52. # Create a user-defined bridge for DB network $ docker network create --subnet=192.168.10.0/24 db-cluster # Run a ClusterControl container $ docker run -d --name clustercontrol --network db-cluster --ip 192.168.10.10 -h clustercontrol -p 5000:80 -p 5001:443 -v /storage/clustercontrol/cmon.d:/etc/cmon.d -v /storage/clustercontrol/datadir:/var/lib/mysql -v /storage/clustercontrol/.ssh:/root/.ssh -v /storage/clustercontrol/backups:/root/backups -e CMON_PASSWORD mysecr3t -e MYSQL_ROOT_PASSWORD mys3cret severalnines/clustercontrol # Restart cmon service inside container $ docker exec -it clustercontrol supervisorctl restart cmon ClusterControl on Docker - Run as Container Copyright 2012 Severalnines AB ● Recommended volumes for data persistence: ○ /etc/cmon.d ○ /var/lib/mysql ○ /root/.ssh ○ /root/backups ● ClusterControl UI is exposed at 80 and 443 by default. ● Service control via supervisord: sshd, mysqld, httpd, cmon, cmon-ssh, cmon-events, cc-auto-deployment ● Run it as: ○ --net=host, if you want this container to manage host or container outside of Docker network. ○ --net={net_name}, if you want CC container to manage containers in the same Docker network.
  • 53. # Run a ClusterControl container $ docker run -d --name=clustercontrol -p 5000:80 -p 5001:443 -h clustercontrol -v /storage/clustercontrol/.ssh:/root/.ssh -v /storage/clustercontrol/datadir:/var/lib/mysql -v /storage/clustercontrol/cmon.d:/etc/cmon.d -v /storage/clustercontrol/backups:/backups severalnines/clustercontrol # Run a 3 node Galera cluster, with auto deployment $ for i in {1..3}; do docker run -d --name galera${i} -p 666{$i}:3306 --link clustercontrol:clustercontrol -e CLUSTER_TYPE=galera -e CLUSTER_NAME=mygalera -e INITIAL_CLUSTER_SIZE=3 severalnines/centos-ssh done ClusterControl on Docker - Auto DB Cluster Deployment Copyright 2012 Severalnines AB ● Use "severalnines/centos-ssh" image - configures passwordless SSH automatically from CC to DB containers and register the container with CC. ● Only Galera is supported (more to come). ● Background script, cc-auto-deployment: ○ Monitors new containers registration. ○ Triggers deployment job if AUTO_DEPLOYMENT=1 (default). ○ Uses ClusterControl CLI, called 's9s' to interact with cmon backend. ● Deployment flow: ○ You create the container. ○ cc-auto-deployment picks up the registered containers and creates a deployment job. ○ ClusterControl deploys the cluster.
  • 54. ClusterControl on Docker - Manual DB Cluster Deployment ● Use "severalnines/centos-ssh" image with AUTO_DEPLOYMENT=0. ● Allows user to have better control on the deployment process initiates by ClusterControl. ● All supported database cluster can be deployed using this method. ● Deployment flow: a. You create the containers. b. You create the database deployment job through ClusterControl UI. c. ClusterControl deploys the cluster. Copyright 2012 Severalnines AB Further Reading - Example at Github: https://github.com/severalnines/docker/tree/master/examples/do cker
  • 55. ClusterControl on Docker - Add Existing DB Containers Copyright 2012 Severalnines AB ● Must be in the same Docker network with the DB containers. ● SSH server and client must be installed and started on the DB containers: ○ Setup passwordless SSH from ClusterControl container to the DB containers. ○ It's going to improve though. Further Reading - Import Existing DB Containers into ClusterControl: https://severalnines.com/blog/clustercontrol-docker
  • 56. Copyright 2017 Severalnines AB Copyright 2017 Severalnines AB What's Next?
  • 57. Copyright 2017 Severalnines AB ● Follow our MySQL on Docker blog series at severalnines.com/blog ● Attend the 2nd MySQL on Docker webinar, MySQL Container Management: ○ Coming Soon in November 2017 ● Deploy DB containers using ClusterControl Docker image. What's Next