A, Docker learn
basic indicators:
(1) docker basic commands to master
(2) the use of a docker install MySQL
(3) the mysql datadir file persistence
(4) and the output document
prerequisites for installing Docker's:
1. Run the 64-bit CPU computer architecture, Docker 32 does not currently support the CPU;
2. run Linux3.8 kernel or higher;
3. One suitable core must support storage drive '
4. kernel must support and open cgroup and namespaces function
in Red Hat-based distributions install Hat and Red Docker:
only a few versions can be installed: RHEL (CentOS) 6 or later (64-bit)
1, check the prerequisites
kernel (version 3.8 or later):
[root@yt-mysql /]# uname -a Linux yt-mysql 3.10.0-957.27.2.el7.x86_64 #1 SMP Mon Jul 29 17:46:05 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
2. Check Device Mapper
used as a storage drive Docker Device Mapper provides storage capacity for the Docker.
[root@yt-mysql /]# ls -l /sys/class/misc/device-mapper/ total 0 -r--r--r-- 1 root root 4096 Apr 1 17:05 dev drwxr-xr-x 2 root root 0 Mar 24 15:35 power lrwxrwxrwx 1 root root 0 Apr 1 17:05 subsystem -> ../../../../class/misc -rw-r--r-- 1 root root 4096 Apr 1 17:05 uevent [root@yt-mysql /]# grep device-mapper /proc/devices 253 device-mapper
3, installation Docker
. 6 mounted in the EPEL RHEL 6 and CentOS
[root@DJ-Test ~]# rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm Retrieving http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm warning: /var/tmp/rpm-tmp.VwJkT5: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... ########################################### [100%] 1:epel-release ########################################### [100%]
After installing EPEL, you can install a Docker
[root@DJ-Test ~]# yum install docker-io
Here it reported an error message, specific performance:
[root@DJ-Test ~]# yum install docker-io Loaded plugins: product-id, search-disabled-repos, security, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Setting up Install Process No package docker-io available. Error: Nothing to do
This is because the source of the problem YUM, YUM So we change the source to install:
yum install https://get.docker.com/rpm/1.7.1/centos-6/RPMS/x86_64/docker-engine-1.7.1-1.el6.x86_64.rpm
Finally, the installation was successful.
Installed: docker-engine.x86_64 0:1.7.1-1.el6 Complete!
Docker installed in RHEL 7
[root@yt-mysql /]# yum install -y docker
The last step will involve detailed article
'Here will be required to install their own dependencies, a total of 14, the installation is complete'
4, start Docker daemon
start Docker daemon in RHEL 6 in:
[root@DJ-Test ~]# service docker start
Add boot:
[root@DJ-Test ~]# service docker enable
Docker start the daemon in RHEL 7 in:
[root@yt-mysql ~]# systemctl start docker
Add boot:
[root@yt-mysql ~]# systemctl enable docker
Check the Docker are installed correctly:
[
root@yt-mysql ~]# docker info Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 1.13.1 ...
So far, Docker has been successfully installed.
MySQL is mounted in the Docker:
1. Retrieve Docker MySQL from the image:
[root@DJ-Test ~]# docker search mysql NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, open-source relati... 9330 [OK] mariadb MariaDB is a community-developed fork of M... 3337 [OK] mysql/mysql-server Optimized MySQL Server Docker images. Crea... 683 [OK] centos/mysql-57-centos7 MySQL 5.7 SQL database server 73 mysql/mysql-cluster Experimental MySQL Cluster Docker images. ... 66 centurylink/mysql Image containing mysql. Optimized to be li... 61 [OK] deitch/mysql-backup REPLACED! Please use http://hub.docker.com... 41 [OK] bitnami/mysql Bitnami MySQL Docker Image 37 [OK] tutum/mysql Base docker image to run a MySQL database ... 34 schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic back... 29 [OK] prom/mysqld-exporter 27 [OK] linuxserver/mysql A Mysql container, brought to you by Linux... 25 circleci/mysql MySQL is a widely used, open-source relati... 19 centos/mysql-56-centos7 MySQL 5.6 SQL database server 19 mysql/mysql-router MySQL Router provides transparent routing ... 15 databack/mysql-backup Back up mysql databases to... anywhere! 13 arey/mysql-client Run a MySQL client from a docker container 13 [OK] openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 ima... 6 genschsa/mysql-employees MySQL Employee Sample Database 5 [OK] fradelg/mysql-cron-backup MySQL/MariaDB database backup using cron t... 5 [OK] devilbox/mysql Retagged MySQL, MariaDB and PerconaDB offi... 2 ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 2 [OK] jelastic/mysql An image of the MySQL database server main... 1 monasca/mysql-init A minimal decoupled init container for mysql 0 widdpim/mysql-client Dockerized MySQL Client (5.7) including Cu... 0 [OK]
2. Download MySQL mirror (do not specify the default version to the latest version)
[root@DJ-Test ~]# docker pull mysql latest: Pulling from mysql 37ede510b7a3: Pull complete 3911f097fce2: Pull complete 34f70da8bdd8: Pull complete 6400f067c12a: Pull complete 009997ca3ce1: Pull complete 60827cd7c6fe: Pull complete 88cb07227133: Pull complete e6a0d8e90c19: Pull complete da3a8a134781: Pull complete d1e05cdd03f3: Pull complete 734f5753825a: Pull complete 91f6f7e6ee30: Pull complete 4ac2941e3fed: Pull complete cd20a0f89bb3: Pull complete 85380da382a8: Pull complete 7fcf40fcc536: Pull complete a120ff19d75b: Pull complete 3a9ab1281854: Pull complete c468355db8c6: Pull complete 2bb4afa2f4a0: Pull complete Digest: sha256:f6eaa1cdc8d9356628ab1813c8c9c809b83f97a177499f8f48590786662ffb84 Status: Downloaded newer image for mysql:latest
3. Check local mirror list
[root@DJ-Test ~]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE mysql latest 2bb4afa2f4a0 35 hours ago 546.6 MB
4. Start mysql vessel, and into the shell command interface: docker run -it docker.io/mysql / bin / bash
[root@yt-mysql ~]# docker run -it docker.io/mysql /bin/bash root@9ac93568df15:/#mysql --version mysql Ver 8.0.19 for Linux on x86_64 (MySQL Community Server - GPL)
5. Run into the container and run MySQL:
[root@yt-mysql ~]# docker run -d --name yutao-mysql -e MYSQL_ROOT_PASSWORD=123456 docker.io/mysql 04e32886d10f843f07456be469297e19ba5226afd76b694e901e1ee8d4a0ea7a [root@yt-mysql ~]# docker exec -it yutao-mysql /bin/bash root@04e32886d10f:/# mysql -uroot -p123456 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.19 MySQL Community Server - GPL Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.01 sec) mysql>
It has entered the MySQL Docker container, you can see the version 8.0.19. But the container thus created have two questions. First, after the container removed, the data is lost, the second is to access the database, you must enter the container inside can.
6. persistent data mapping MySQL open ports:
(1) create a host data storage directory
[root@yt-mysql opt]# mkdir -p /opt/data/mysql
(2) starting container
[root@yt-mysql opt]# docker run -d -v /opt/data/mysql/:/var/lib/mysql -p 3306:3306 --name yutao-mysql -e MYSQL_ROOT_PASSWORD=123456 docker.io/mysql dec3ef637194140c1860d3796f9a82651c4c7000403c7651e8765f2651627306 /usr/bin/docker-current: Error response from daemon: driver failed programming external connectivity on endpoint yutao-mysql (c2b29723576d6f955dc924689b02c658d0c01b238b0fa304b033fb8db653d6a3): Error starting userland proxy: listen tcp 0.0.0.0:3306: bind: address already in use.
- here it is given, suggesting that 3306 port is occupied, because MySQL is using this port, so I will change it to 3307
[root@yt-mysql ~]# docker run -d -v /opt/data/mysql/:/var/lib/mysql -p 3307:3306 --name yutao-mysql -e MYSQL_ROOT_PASSWORD=123456 docker.io/mysql 5e1b807053e5f77205b6d6e325c894151a21ef745912004d9b12dcb1bf93b16d
- Well, a successful start
to look at the relevant information:
[root@yt-mysql ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5e1b807053e5 docker.io/mysql "docker-entrypoint..." 4 minutes ago Up 4 minutes 33060/tcp, 0.0.0.0:3307->3306/tcp yutao-mysql [root@yt-mysql mysql]# ls /opt/data/mysql/ auto.cnf binlog.index client-cert.pem ibdata1 ibtmp1 mysql.ibd public_key.pem sys binlog.000001 ca-key.pem client-key.pem ib_logfile0 #innodb_temp performance_schema server-cert.pem undo_001 binlog.000002 ca.pem ib_buffer_pool ib_logfile1 mysql private_key.pem server-key.pem undo_002
Docker install and replace MySQL my.cnf:
first check the version of MySQL remote and pulling download to view mirror, the front have implemented, is omitted here
to view mirror:
[root@yt-mysql ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/mysql latest 9228ee8bac7a 2 days ago 547 MB
Create a temporary MySQL, into the container:
[root@yt-mysql ~]# docker run --rm --name mysqlTemp -it -v /usr/local/mysql/:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql /bin/bash root@03034135a5fb:/#
--rm container will delete itself after exiting the container, -it = -i -t is an interactive mode, / bin / bash is a command-line mode to enter the
check my.cnf file:
root@03034135a5fb:/etc# cat /etc/mysql/my.cnf # Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # The MySQL Server configuration file. # # For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html [mysqld] pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql secure-file-priv= NULL # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Custom config should go here !includedir /etc/mysql/conf.d/
Copy the configuration file: copy file /etc/mysql/my.cnf in Docker to / Docker the / var / lib / mysql directory, and the host / usr / local / mysql directory
root@03034135a5fb:/etc# cp /etc/mysql/my.cnf /var/lib/mysql root@03034135a5fb:/etc/mysql# cp -R conf.d/ /var/lib/mysql/conf.d
Exit bash, Docker in makeshift mysqlTemp is deleted, all profiles have mysql under the View host / usr / local / mysql directory
[root@yt-mysql mysql]# ls /usr/local/mysql/ bin conf.d COPYING docs include lib man my.cnf README share support-files
Modify the configuration file, and then create a formal MySQL container:
docker run --name yutao-mysql -p 3307:3306 -e MYSQL_ROOT_PASSWORD=123456 -v /usr/local/mysql/data:/var/lib/mysql -v /usr/local/mysql/my.cnf:/etc/mysql/my.cnf -d docker.io/mysql
This article is the original author, if you need to reprint, please credit: https://www.cnblogs.com/qq1148932219/p/12626893.html
Annex: Docker installation detailed procedure
[root@yt-mysql /]# yum install -y docker Loaded plugins: fastestmirror Determining fastest mirrors epel/x86_64/metalink | 7.1 kB 00:00:00 * base: mirrors.cn99.com * epel: mirrors.njupt.edu.cn * extras: mirrors.ustc.edu.cn * updates: mirrors.cn99.com base | 3.6 kB 00:00:00 epel | 4.7 kB 00:00:00 extras | 2.9 kB 00:00:00 mysql-connectors-community | 2.5 kB 00:00:00 mysql-tools-community | 2.5 kB 00:00:00 mysql57-community | 2.5 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/5): epel/x86_64/group_gz | 95 kB 00:00:00 (2/5): epel/x86_64/updateinfo | 1.0 MB 00:00:00 (3/5): extras/7/x86_64/primary_db | 165 kB 00:00:00 (4/5): epel/x86_64/primary_db | 6.8 MB 00:00:00 (5/5): updates/7/x86_64/primary_db | 7.6 MB 00:00:02 Resolving Dependencies --> Running transaction check ---> Package docker.x86_64 2:1.13.1-109.gitcccb291.el7.centos will be installed --> Processing Dependency: docker-common = 2:1.13.1-109.gitcccb291.el7.centos for package: 2:docker-1.13.1-109.gitcccb291.el7.centos.x86_64 --> Processing Dependency: docker-client = 2:1.13.1-109.gitcccb291.el7.centos for package: 2:docker-1.13.1-109.gitcccb291.el7.centos.x86_64 --> Processing Dependency: subscription-manager-rhsm-certificates for package: 2:docker-1.13.1-109.gitcccb291.el7.centos.x86_64 --> Processing Dependency: libseccomp.so.2()(64bit) for package: 2:docker-1.13.1-109.gitcccb291.el7.centos.x86_64 --> Running transaction check ---> Package docker-client.x86_64 2:1.13.1-109.gitcccb291.el7.centos will be installed ---> Package docker-common.x86_64 2:1.13.1-109.gitcccb291.el7.centos will be installed --> Processing Dependency: skopeo-containers >= 1:0.1.26-2 for package: 2:docker-common-1.13.1-109.gitcccb291.el7.centos.x86_64 --> Processing Dependency: oci-umount >= 2:2.3.3-3 for package: 2:docker-common-1.13.1-109.gitcccb291.el7.centos.x86_64 --> Processing Dependency: oci-systemd-hook >= 1:0.1.4-9 for package: 2:docker-common-1.13.1-109.gitcccb291.el7.centos.x86_64 --> Processing Dependency: oci-register-machine >= 1:0-5.13 for package: 2:docker-common-1.13.1-109.gitcccb291.el7.centos.x86_64 --> Processing Dependency: container-storage-setup >= 0.9.0-1 for package: 2:docker-common-1.13.1-109.gitcccb291.el7.centos.x86_64 --> Processing Dependency: container-selinux >= 2:2.51-1 for package: 2:docker-common-1.13.1-109.gitcccb291.el7.centos.x86_64 --> Processing Dependency: atomic-registries for package: 2:docker-common-1.13.1-109.gitcccb291.el7.centos.x86_64 ---> Package libseccomp.x86_64 0:2.3.1-3.el7 will be installed ---> Package subscription-manager-rhsm-certificates.x86_64 0:1.24.13-4.el7.centos will be installed --> Running transaction check ---> Package atomic-registries.x86_64 1:1.22.1-29.gitb507039.el7 will be installed --> Processing Dependency: python-pytoml for package: 1:atomic-registries-1.22.1-29.gitb507039.el7.x86_64 ---> Package container-selinux.noarch 2:2.107-3.el7 will be installed ---> Package container-storage-setup.noarch 0:0.11.0-2.git5eaf76c.el7 will be installed ---> Package containers-common.x86_64 1:0.1.37-3.el7.centos will be installed ---> Package oci-register-machine.x86_64 1:0-6.git2b44233.el7 will be installed ---> Package oci-systemd-hook.x86_64 1:0.2.0-1.git05e6923.el7_6 will be installed --> Processing Dependency: libyajl.so.2()(64bit) for package: 1:oci-systemd-hook-0.2.0-1.git05e6923.el7_6.x86_64 ---> Package oci-umount.x86_64 2:2.5-3.el7 will be installed --> Running transaction check ---> Package python-pytoml.noarch 0:0.1.14-1.git7dea353.el7 will be installed ---> Package yajl.x86_64 0:2.0.4-4.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================================= Package Arch Version Repository Size ======================================================================================================================================================= Installing: docker x86_64 2:1.13.1-109.gitcccb291.el7.centos extras 18 M Installing for dependencies: atomic-registries x86_64 1:1.22.1-29.gitb507039.el7 extras 35 k container-selinux noarch 2:2.107-3.el7 extras 39 k container-storage-setup noarch 0.11.0-2.git5eaf76c.el7 extras 35 k containers-common x86_64 1:0.1.37-3.el7.centos extras 21 k docker-client x86_64 2:1.13.1-109.gitcccb291.el7.centos extras 3.9 M docker-common x86_64 2:1.13.1-109.gitcccb291.el7.centos extras 98 k libseccomp x86_64 2.3.1-3.el7 base 56 k oci-register-machine x86_64 1:0-6.git2b44233.el7 extras 1.1 M oci-systemd-hook x86_64 1:0.2.0-1.git05e6923.el7_6 extras 34 k oci-umount x86_64 2:2.5-3.el7 extras 33 k python-pytoml noarch 0.1.14-1.git7dea353.el7 extras 18 k subscription-manager-rhsm-certificates x86_64 1.24.13-4.el7.centos updates 228 k yajl x86_64 2.0.4-4.el7 base 39 k Transaction Summary ======================================================================================================================================================= Install 1 Package (+13 Dependent packages) Total download size: 23 M Installed size: 81 M Downloading packages: (1/14): container-selinux-2.107-3.el7.noarch.rpm | 39 kB 00:00:00 (2/14): atomic-registries-1.22.1-29.gitb507039.el7.x86_64.rpm | 35 kB 00:00:00 (3/14): containers-common-0.1.37-3.el7.centos.x86_64.rpm | 21 kB 00:00:00 (4/14): container-storage-setup-0.11.0-2.git5eaf76c.el7.noarch.rpm | 35 kB 00:00:00 (5/14): docker-1.13.1-109.gitcccb291.el7.centos.x86_64.rpm | 18 MB 00:00:02 (6/14): docker-client-1.13.1-109.gitcccb291.el7.centos.x86_64.rpm | 3.9 MB 00:00:02 (7/14): docker-common-1.13.1-109.gitcccb291.el7.centos.x86_64.rpm | 98 kB 00:00:00 (8/14): oci-umount-2.5-3.el7.x86_64.rpm | 33 kB 00:00:00 (9/14): python-pytoml-0.1.14-1.git7dea353.el7.noarch.rpm | 18 kB 00:00:00 (10/14): oci-register-machine-0-6.git2b44233.el7.x86_64.rpm | 1.1 MB 00:00:00 (11/14): oci-systemd-hook-0.2.0-1.git05e6923.el7_6.x86_64.rpm | 34 kB 00:00:00 (12/14): libseccomp-2.3.1-3.el7.x86_64.rpm | 56 kB 00:00:00 (13/14): subscription-manager-rhsm-certificates-1.24.13-4.el7.centos.x86_64.rpm | 228 kB 00:00:00 (14/14): yajl-2.0.4-4.el7.x86_64.rpm | 39 kB 00:00:00 ------------------------------------------------------------------------------------------------------------------------------------------------------- Total 8.1 MB/s | 23 MB 00:00:02 Running transaction check Running transaction test Transaction test succeeded Running transaction Warning: RPMDB altered outside of yum. Installing : yajl-2.0.4-4.el7.x86_64 1/14 Installing : 2:oci-umount-2.5-3.el7.x86_64 2/14 Installing : 1:oci-systemd-hook-0.2.0-1.git05e6923.el7_6.x86_64 3/14 Installing : python-pytoml-0.1.14-1.git7dea353.el7.noarch 4/14 Installing : 1:atomic-registries-1.22.1-29.gitb507039.el7.x86_64 5/14 Installing : 2:container-selinux-2.107-3.el7.noarch 6/14 setsebool: SELinux is disabled. Installing : libseccomp-2.3.1-3.el7.x86_64 7/14 Installing : subscription-manager-rhsm-certificates-1.24.13-4.el7.centos.x86_64 8/14 Installing : 1:containers-common-0.1.37-3.el7.centos.x86_64 9/14 Installing : 1:oci-register-machine-0-6.git2b44233.el7.x86_64 10/14 Installing : container-storage-setup-0.11.0-2.git5eaf76c.el7.noarch 11/14 Installing : 2:docker-common-1.13.1-109.gitcccb291.el7.centos.x86_64 12/14 Installing : 2:docker-client-1.13.1-109.gitcccb291.el7.centos.x86_64 13/14 Installing : 2:docker-1.13.1-109.gitcccb291.el7.centos.x86_64 14/14 Verifying : 2:oci-umount-2.5-3.el7.x86_64 1/14 Verifying : 1:oci-systemd-hook-0.2.0-1.git05e6923.el7_6.x86_64 2/14 Verifying : container-storage-setup-0.11.0-2.git5eaf76c.el7.noarch 3/14 Verifying : 1:oci-register-machine-0-6.git2b44233.el7.x86_64 4/14 Verifying : 1:containers-common-0.1.37-3.el7.centos.x86_64 5/14 Verifying : subscription-manager-rhsm-certificates-1.24.13-4.el7.centos.x86_64 6/14 Verifying : libseccomp-2.3.1-3.el7.x86_64 7/14 Verifying : 2:docker-client-1.13.1-109.gitcccb291.el7.centos.x86_64 8/14 Verifying : 2:container-selinux-2.107-3.el7.noarch 9/14 Verifying : yajl-2.0.4-4.el7.x86_64 10/14 Verifying : python-pytoml-0.1.14-1.git7dea353.el7.noarch 11/14 Verifying : 1:atomic-registries-1.22.1-29.gitb507039.el7.x86_64 12/14 Verifying : 2:docker-common-1.13.1-109.gitcccb291.el7.centos.x86_64 13/14 Verifying : 2:docker-1.13.1-109.gitcccb291.el7.centos.x86_64 14/14 Installed: docker.x86_64 2:1.13.1-109.gitcccb291.el7.centos Dependency Installed: atomic-registries.x86_64 1:1.22.1-29.gitb507039.el7 container-selinux.noarch 2:2.107-3.el7 container-storage-setup.noarch 0:0.11.0-2.git5eaf76c.el7 containers-common.x86_64 1:0.1.37-3.el7.centos docker-client.x86_64 2:1.13.1-109.gitcccb291.el7.centos docker-common.x86_64 2:1.13.1-109.gitcccb291.el7.centos libseccomp.x86_64 0:2.3.1-3.el7 oci-register-machine.x86_64 1:0-6.git2b44233.el7 oci-systemd-hook.x86_64 1:0.2.0-1.git05e6923.el7_6 oci-umount.x86_64 2:2.5-3.el7 python-pytoml.noarch 0:0.1.14-1.git7dea353.el7 subscription-manager-rhsm-certificates.x86_64 0:1.24.13-4.el7.centos yajl.x86_64 0:2.0.4-4.el7 Complete!