Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

MySQL docker with demo by Ramana Yeruva

107 views

Published on

Insights on MySQL Docker with the demonstration of the same.

Published in: Engineering
  • Be the first to comment

  • Be the first to like this

MySQL docker with demo by Ramana Yeruva

  1. 1. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
  2. 2. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | MySQL – Docker Ramana Yeruva SystemQA,MySQL April 27, 2018 2
  3. 3. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 3
  4. 4. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | MySQL Docker with Demo • What is Docker • Docker Terminology • MySQL Docker images and contents • Docker commands • MySQL server deployments with Docker Images • MySQL upgrades • Demo Confidential – Oracle Internal/Restricted/Highly Restricted 4
  5. 5. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | What is Docker 5 ● Docker is a Linux container. It deploys every application as a series of binary layers, containing not only the minimum dependencies (libraries and applications) to make the service work but also full installation of OS. Ex:The MySQL image for instance has a full OracleLinux installation ● It stores images in a central registry, from where the docker client can download them quickly ● By its definition, it is lightweight. If you have the images already in your system, deployment of the service happens in seconds. ● Docker can run applications in various flavors of Linux at once. It actually makes the Linux flavor dependency transparent, to the point that the users barely realize that
  6. 6. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Docker Terminology 6 • Docker file is the script that builds a Docker image • Docker Hub is the official online repo for Docker images. When you run the "docker" command on your Linux system in order to start a new Docker image, the image gets downloaded from Docker Hub. ● Docker can be linked to online source repositories such as github to enable automatic image builds. ● MySQL team maintains 2 set of images. "mysql": The docker-owned image maintained both by docker and by oracle team. Based on Debian "mysql/mysql-server" : Owned and maintained by Oracle. Based on OracleLinux • Image:A pre-packaged application and its dependencies. • Container:A running instance of an image.
  7. 7. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Docker Image and contents 7 ● Docker images for MySQL are optimized for code size, which means they only include crucial components that are expected to be relevant for the majority of users who run MySQL instances in Docker containers. A MySQL Docker installation is different from a common, non-Docker installation in the following aspects: ● Included binaries are limited to: ● /usr/bin/my_print_defaults ● /usr/bin/mysql ● /usr/bin/mysql_config ● /usr/bin/mysql_install_db ● /usr/bin/mysql_tzinfo_to_sql ● /usr/bin/mysql_upgrade ● /usr/bin/mysqladmin ● /usr/bin/mysqlcheck ● /usr/bin/mysqldump ● /usr/bin/mysqlpump ● /usr/sbin/mysqld We also strip away all debug symbols from the binaries, since these symbols make up almost 90% of the total file size.
  8. 8. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Docker Commands 8 ● docker pull: pull specified docker image from docker hub or from published location ● docker run: run server inside container with options ● docker ps: list the processes started with docker ● docker rmi:remove the image ● docker rm:remove the container ● docker start/stop/restart:start/stop/restart container ● docker logs:watch logs by docker container ● docker exec:execute commands inside container etc ● docker inspect: to see with which parameters container started,This command returns a JSON file containing all the details about the container ● docker images -a:list pulled images from docker hub or from local published location
  9. 9. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | MySQL Deployments with docker images 9 ● Downloading a MySQL Server Docker Image ● Starting a MySQL Server Instance ● Connecting to MySQL Server from within the Container ● Container Shell Access ● Server Error Log ● Docker Environment Variables ● Stopping and Deleting a MySQL Container
  10. 10. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Download a MySQL Docker Image 10 Pulling docker images from docker registry on one of our lab hosts(mydocker.no.oracle.com) docker pull mydocker.no.oracle.com/qa/mysql-{package_type}-server:tag {package_type}:enterprise for enterprise package and if not specified it is community Tag: different server versions:https://hub.docker.com/r/mysql/mysql-server/tags/ MySQL Server 5.5 (tag: 5.5, 5.5.60, 5.5.60-1.1.5) (mysql-server/5.5/Dockerfile) MySQL Server 5.6 (tag: 5.6, 5.6.40, 5.6.40-1.1.5) (mysql-server/5.6/Dockerfile) MySQL Server 5.7, the latest GA-1 (tag: 5.7, 5.7.22, 5.7.22-1.1.5) (mysql-server/5.7/Dockerfile) MySQL Server 8.0, the latest GA (tag: 8.0, 8.0.11, 8.0.11-1.1.5) (mysql-server/8.0/Dockerfile) Ex:docker pull mydocker.no.oracle.com/qa/mysql-enterprise-server:8.0.11 docker pull mydocker.no.oracle.com/qa/mysql-server:8.0.11 [root@frigg12 docker_test]# docker images -a | grep mysql-enterprise mydocker.no.oracle.com/qa/mysql-enterprise-server 8.0.11 c4ebca134df5 4 days ago 290MB mydocker.no.oracle.com/qa/mysql-enterprise-server 5.7.22 55bb21ef08fd 3 weeks ago 248MB
  11. 11. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Starting a MySQL Server Instance 11 docker run --name server8011 -e MYSQL_ROOT_PASSWORD='root' -p 3307:3306 -v /tmp/server8011:/var/lib/mysql -v /export/home2/tmp/ramana/docker_test/my80.log:/var/log/mysqld.log -d mydocker.no.oracle.com/qa/mysql-server:8.0.11 mysqld –log-error=/var/log/mysqld.log Server8011:name of the container MYSQL_ROOT_PASSWORD:bring up server with given password by default -p:mapping of 3306 port with 3307 on the host where container started -v(volume):mounting server parameter paths to the host where container started If no “-v” then after container stopped datadir,log info is gone. They are not persist if they are not mounted to outside container --->more options in upcoming slides.... docker logs server8011 -->shows the log of the container
  12. 12. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Connecting to server with in container 12 [root@frigg12 docker_test]# docker exec -t server8011enterprise mysql -uroot -proot -e "select user,host,plugin from mysql.user;" mysql: [Warning] Using a password on the command line interface can be insecure. +------------------+-----------+-----------------------+ | user | host | plugin | +------------------+-----------+-----------------------+ | healthchecker | localhost | caching_sha2_password | | mysql.infoschema | localhost | mysql_native_password | | mysql.session | localhost | mysql_native_password | | mysql.sys | localhost | mysql_native_password | | root | localhost | caching_sha2_password | +------------------+-----------+-----------------------+
  13. 13. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Container Shell Access 13 [root@frigg12 docker_test]# docker exec -it server8011enterprise bash bash-4.2# ls /var/lib/mysql auto.cnf binlog.index client-cert.pem ib_logfile0 ibtmp1 mysql.sock private_key.pem server-key.pem undo_002 binlog.000001 ca-key.pem client-key.pem ib_logfile1 mysql mysql.sock.lock public_key.pem sys binlog.000002 ca.pem ib_buffer_pool ibdata1 mysql.ibd performance_schema server-cert.pem undo_001 bash-4.2# mysql -uroot -proot -e "select version();" mysql: [Warning] Using a password on the command line interface can be insecure. +-------------------+ | version() | +-------------------+ | 8.0.11-commercial | +-------------------+ bash-4.2# hostname bash: hostname: command not found
  14. 14. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Server Error Log 14 ● When the MySQL Server is first started with your server container, a server error log is NOT generated if either of the following conditions is true: ● A server configuration file from the host has been mounted, but the file does not contain the system variable log_error ● A server configuration file from the host has not been mounted, but the Docker environment variable MYSQL_LOG_CONSOLE is true (which is the variable's default state for MySQL 8.0 server containers). The MySQL Server's error log is then redirected to stderr, so that the error log goes into the Docker container's log and is viewable using the docker logs mysqld-container command. ● To make MySQL Server generate an error log when either of the two conditions is true, use the --log-error option to configure the server to generate the error log at a specific location inside the container. To persist the error log, mount a host file at the location of the error log inside the container as explained in Persisting Data and Configuration Changes. However, you must make sure your MySQL Server inside its container has write access to the mounted host file. ● Using Docker's log interface is recommended which is default in 8.0 ● Ex:docker run --name server8011enterprise -e MYSQL_ROOT_PASSWORD='root' -p 3307:3306 -v /tmp/server8011enterprise:/var/lib/mysql -v /export/home2/tmp/ramana/docker_test/my80.log:/var/log/mysqld.log -d mydocker.no.oracle.com/qa/mysql-enterprise-server:8.0.11 –log-error=/var/log/mysqld.log -->log-error generate log in my80.log, otherwise it writes into docker log console
  15. 15. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Docker Environment Variables 15 When you create a MySQL Server container, you can configure the MySQL instance by using the --env option (-e in short) and specifying one or more of the following environment variables. ● MYSQL_RANDOM_ROOT_PASSWORD ● MYSQL_ONETIME_PASSWORD ● MYSQL_DATABASE ● MYSQL_USER, MYSQL_PASSWORD ● MYSQL_ROOT_HOST ● MYSQL_LOG_CONSOLE ● MYSQL_ROOT_PASSWORD ● MYSQL_ALLOW_EMPTY_PASSWORD
  16. 16. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Docker Environment Variables 16 MYSQL_RANDOM_ROOT_PASSWORD When this variable is true (which is its default state, unless MYSQL_ROOT_PASSWORD is set or MYSQL_ALLOW_EMPTY_PASSWORD is set to true), a random password for the server's root user is generated when the Docker container is started. The password is printed to stdout of the container and can be found by looking at the container’s log MYSQL_ONETIME_PASSWORD When the variable is true (which is its default state, unless MYSQL_ROOT_PASSWORD is set or MYSQL_ALLOW_EMPTY_PASSWORD is set to true), the root user's password is set as expired and must be changed before MySQL can be used normally. This variable is only supported for MySQL 5.6 and later MYSQL_DATABASE This variable allows you to specify the name of a database to be created on image startup. If a user name and a password are supplied with MYSQL_USER and MYSQL_PASSWORD, the user is created and granted superuser access to this database (corresponding to GRANT ALL). The specified database is created by a CREATE DATABASE IF NOT EXIST statement, so that the variable has no effect if the database already exists MYSQL_USER, MYSQL_PASSWORD These variables are used in conjunction to create a user and set that user's password, and the user is granted superuser permissions for the database specified by the MYSQL_DATABASE variable. Both MYSQL_USER and MYSQL_PASSWORD are required for a user to be created; if any of the two variables is not set, the other is ignored. If both variables are set but MYSQL_DATABASE is not, the user is created without any privileges.
  17. 17. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Docker Environment Variables 17 MYSQL_ROOT_HOST By default, MySQL creates the 'root'@'localhost' account. This account can only be connected to from inside the container. To allow root connections from other hosts, set this environment variable. For example, the value 172.17.0.1, which is the default Docker gateway IP, allows connections from the host machine that runs the container. The option accepts only one entry, but wildcards are allowed (for example, MYSQL_ROOT_HOST=172.*.*.* or MYSQL_ROOT_HOST=%) MYSQL_ROOT_PASSWORD This variable specifies a password that is set for the MySQL root account. Warning Setting the MySQL root user password on the command line is insecure. As an alternative to specifying the password explicitly, you can set the variable with a container file path for a password file, and then mount a file from your host that contains the password at the container file path. This is still not very secure, as the location of the password file is still exposed. It is preferable to use the default settings of MYSQL_RANDOM_ROOT_PASSWORD and MYSQL_ONETIME_PASSWORD being both true. MYSQL_ALLOW_EMPTY_PASSWORD Set it to true to allow the container to be started with a blank password for the root user. Warning Setting this variable to true is insecure, because it is going to leave your MySQL instance completely unprotected, allowing anyone to gain complete superuser access. It is preferable to use the default settings of MYSQL_RANDOM_ROOT_PASSWORD and MYSQL_ONETIME_PASSWORD being both true. MYSQL_LOG_CONSOLE When the variable is true (which is its default state for MySQL 8.0 server containers), the MySQL Server's error log is redirected to stderr, so that the error log goes into the Docker container's log and is viewable using the docker logs command.
  18. 18. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Stopping and Deleting Container 18 docker stop container_name{id} docker rm container_name{id} docker kill container_name{id} docker ps -a | grep enterprise 534cc94e08ef mydocker.no.oracle.com/qa/mysql-enterprise-server:8.0.11 "/entrypoint.sh --..." 23 minutes ago Up 23 minutes (healthy) 33060/tcp, 0.0.0.0:3307->3306/tcp server8011enterprise [root@frigg12 docker_test]# docker stop server8011enterprise server8011enterprise [root@frigg12 docker_test]# docker ps -a | grep enterprise 534cc94e08ef mydocker.no.oracle.com/qa/mysql-enterprise-server:8.0.11 "/entrypoint.sh --..." 23 minutes ago Exited (0) 2 seconds ago server8011enterprise [root@frigg12 docker_test]# docker ps -a | grep server8011enterprise b630845518e5 mydocker.no.oracle.com/qa/mysql-enterprise-server:8.0.11 "/entrypoint.sh my..." About an hour ago Up 2 minutes (healthy) 33060/tcp, 0.0.0.0:3307->3306/tcp server8011enterprise [root@frigg12 docker_test]# docker kill server8011enterprise<--which does a hard shutdown of the container Server8011enterprise [root@frigg12 docker_test]# docker ps -a | grep server8011enterprise b630845518e5 mydocker.no.oracle.com/qa/mysql-enterprise-server:8.0.11 "/entrypoint.sh my..." About an hour ago Exited (137) 2 seconds ago server8011enterprise [root@frigg12 docker_test]# docker rm server8011enterprise server8011enterprise [root@frigg12 docker_test]# docker ps -a | grep enterprise
  19. 19. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | MySQL Upgrades 19 In principle, upgrading is the same as for upgrading any other server package, but it will generally be necessary to have mapped the datadir in some way with -v: 1. Stop old server 2. Replace old server binaries with new (for Docker this just means pulling the new image) 3. Start new server (docker run, with a -v that maps the same data location to var/lib/mysql 4. Run mysql_upgrade (docker exec <container from 3.> -it mysql_upgrade -uroot -p) 5. Restart server (docker restart <container from 3.>)
  20. 20. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Demo 20
  21. 21. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Thank You! 21
  22. 22. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 22
  23. 23. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |

×