1.9 docker-contos7 架构mysql5.7

一、查找Docker Hub上的mysql镜像

   找到与你的操作系统一致的版本号,当前服务器为contos 7,故需下载centos/mysql-57-centos7 版本

root@itpux docker.service.d]# docker search mysql
INDEX       NAME                                                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/mysql                                                  MySQL is a widely used, open-source relati...   7361      [OK]       
docker.io   docker.io/mariadb                                                MariaDB is a community-developed fork of M...   2368      [OK]       
docker.io   docker.io/mysql/mysql-server                                     Optimized MySQL Server Docker images. Crea...   546                  [OK]
docker.io   docker.io/zabbix/zabbix-server-mysql                             Zabbix Server with MySQL database support       143                  [OK]
docker.io   docker.io/hypriot/rpi-mysql                                      RPi-compatible Docker Image with Mysql          101                  
docker.io   docker.io/zabbix/zabbix-web-nginx-mysql                          Zabbix frontend based on Nginx web-server ...   76                   [OK]
docker.io   docker.io/centurylink/mysql                                      Image containing mysql. Optimized to be li...   59                   [OK]
docker.io   docker.io/1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5   ubuntu-16-nginx-php-phpmyadmin-mysql-5          47                   [OK]
docker.io   docker.io/centos/mysql-57-centos7                                MySQL 5.7 SQL database server                   42                   
docker.io   docker.io/mysql/mysql-cluster                                    Experimental MySQL Cluster Docker images. ...   35                   
docker.io   docker.io/tutum/mysql                                            Base docker image to run a MySQL database ...   31                   
docker.io   docker.io/schickling/mysql-backup-s3                             Backup MySQL to S3 (supports periodic back...   23                   [OK]
docker.io   docker.io/bitnami/mysql                                          Bitnami MySQL Docker Image                      21                   [OK]
docker.io   docker.io/linuxserver/mysql                                      A Mysql container, brought to you by Linux...   17                   
docker.io   docker.io/zabbix/zabbix-proxy-mysql                              Zabbix proxy with MySQL database support        17                   [OK]
docker.io   docker.io/centos/mysql-56-centos7                                MySQL 5.6 SQL database server                   11                   
docker.io   docker.io/circleci/mysql                                         MySQL is a widely used, open-source relati...   7                    
docker.io   docker.io/openshift/mysql-55-centos7                             DEPRECATED: A Centos7 based MySQL v5.5 ima...   6                    
docker.io   docker.io/dsteinkopf/backup-all-mysql                            backup all DBs in a mysql server                5                    [OK]
docker.io   docker.io/mysql/mysql-router                                     MySQL Router provides transparent routing ...   5                    
docker.io   docker.io/jelastic/mysql                                         An image of the MySQL database server main...   1                    
docker.io   docker.io/openzipkin/zipkin-mysql                                Mirror of https://quay.io/repository/openz...   1                    
docker.io   docker.io/ansibleplaybookbundle/mysql-apb                        An APB which deploys RHSCL MySQL                0                    [OK]
docker.io   docker.io/cloudfoundry/cf-mysql-ci                               Image used in CI of cf-mysql-release            0                    
docker.io   docker.io/cloudposse/mysql                                       Improved `mysql` service with support for ...   0                    [OK]

 

 

 二、下载docker.io/mysql源,增加版本号,如下:

[root@itpux docker.service.d]# docker pull docker.io/mysql:5.7
Trying to pull repository docker.io/library/mysql ...
5.7: Pulling from docker.io/library/mysql
a5a6f2f73cd8: Already exists
936836019e67: Already exists
283fa4c95fb4: Already exists
1f212fb371f9: Already exists
e2ae0d063e89: Already exists
5ed0ae805b65: Pull complete
0283dc49ef4e: Pull complete
a7905d9fbbea: Pull complete
cd2a65837235: Pull complete
5f906b8da5fe: Pull complete
e81e51815567: Pull complete
Digest: sha256:c23e9bfe66eeffc990cf6bce4bb0e9c5c85eb908170f3b3dde3e9a12c5a91689
Status: Downloaded newer image for docker.io/mysql:5.7

 

  三、查看镜像

[root@itpux ~]# docker images 
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
boonya/tomcat-web         latest              48509e67ce6e        About an hour ago   595.7 MB
<none>                    <none>              29e96687db4a        2 hours ago         300.1 MB
nginxdocker/nginxdocker   v1                  4700aa51860f        5 hours ago         415.2 MB
mysql                     latest              2dd01afbe8df        18 hours ago        485.5 MB
centos/mysql-57-centos7   latest              b996585055be        2 weeks ago         448.1 MB
centos                    latest              75835a67d134        2 weeks ago         200.4 MB
[root@itpux ~]# 

 

 

四、进行镜像安装,并查看是否运行

[root@itpux mysql]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx_mysql v1 caf1cb01c233 2 weeks ago 415.2 MB
mysql latest 2dd01afbe8df 2 weeks ago 485.5 MB
centos latest 75835a67d134 4 weeks ago 200.4 MB
[root@itpux mysql]#docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/mysql/log/mysql -v $PWD/data:/mysql/app/mysql/data -it mysql:latest

 
6b8026bc7a9c0a12778e8ce768de4a1b45c704087a21da6403ea6d50f43a3c31
[root@itpux mysql]#

 

命令说明:

  • -p 3306:3306:将容器的 3306 端口映射到主机的 3306 端口。

  • -v -v $PWD/conf:/etc/mysql/conf.d:将主机当前目录下的 conf/my.cnf 挂载到容器的 /etc/mysql/my.cnf。

  • -v $PWD/logs:/logs:将主机当前目录下的 logs 目录挂载到容器的 /logs。

  • -v $PWD/data:/var/lib/mysql :将主机当前目录下的data目录挂载到容器的 /var/lib/mysql 。

  • -e MYSQL_ROOT_PASSWORD=123456:初始化 root 用户的密码。

 

 

 五、查看MYSQL容器IP地址和登陆MYSQL,因容器IP地址是动态分配 ,故虚拟机不能关机和不能关docker,关机后需要重新核实容器IP地址

[root@itpux ~]# docker inspect mymysql | grep ipaddress -i
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.5",
                    "IPAddress": "172.17.0.5",
[root@itpux ~]# ping 172.17.0.5
PING 172.17.0.5 (172.17.0.5) 56(84) bytes of data.
64 bytes from 172.17.0.5: icmp_seq=1 ttl=64 time=0.144 ms
^C
--- 172.17.0.5 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.144/0.144/0.144/0.000 ms

二、安装mysql登录客户端

root@docker2 ~]# yum install -y mariadb
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 mariadb.x86_64.3.10.1.20-2.el7 将被 安装
--> 正在处理依赖关系 mariadb-libs(x86-64) = 3:10.1.20-2.el7,它被软件包 3:mariadb-10.1.20-2.el7.x86_64 需要
--> 正在处理依赖关系 mariadb-common(x86-64) = 3:10.1.20-2.el7,它被软件包 3:mariadb-10.1.20-2.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mariadb-common.x86_64.3.10.1.20-2.el7 将被 安装
--> 正在处理依赖关系 /etc/my.cnf,它被软件包 3:mariadb-common-10.1.20-2.el7.x86_64 需要
---> 软件包 mariadb-libs.x86_64.1.5.5.56-2.el7 将被 升级
---> 软件包 mariadb-libs.x86_64.3.10.1.20-2.el7 将被 更新
--> 正在检查事务
---> 软件包 mariadb-config.x86_64.3.10.1.20-2.el7 将被 安装

 





[root@itpux
~]# mysql -uroot -p123456 -h172.17.0.5 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 2 Server version: 5.7.21 MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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>

 六、镜像容器并打包下载

[root@itpux ~]# docker ps -a
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS                      PORTS                    NAMES
9afe5b71fca3        centos/mysql-57-centos7      "container-entrypoint"   6 minutes ago       Exited (0) 5 seconds ago                             mymysql
e9247345411c        centos                       "/bin/bash"              25 minutes ago      Exited (0) 22 minutes ago                            mysqldb
634bbc0a8968        boonya/tomcat-web:latest     "/bin/sh -c '/usr/loc"   About an hour ago   Up About an hour            0.0.0.0:8088->8080/tcp   reverent_brown
576d0f72377c        centos                       "/bin/bash"              2 hours ago         Up 2 hours                                           nginxdocker02
34abed4c4e6f        nginxdocker/nginxdocker:v1   "nginx"                  5 hours ago         Up 2 hours                  0.0.0.0:8080->80/tcp     nginxserver
[root@itpux ~]# docker commit -m "contos7-mysql5.7" 9afe5b71fca38d7c86e69bf7fe3283092fdc0b7cea1bb922b8b1928143ecf460 contos/mysql5.7:v1
sha256:0d8579c7da5f6001e3e4bd2436339eac45042ad107c319ba2c48a34d24a81822
[root@itpux ~]# docker images 
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
contos/mysql5.7           v1                  0d8579c7da5f        7 seconds ago       488.7 MB
boonya/tomcat-web         latest              48509e67ce6e        About an hour ago   595.7 MB
<none>                    <none>              29e96687db4a        2 hours ago         300.1 MB
nginxdocker/nginxdocker   v1                  4700aa51860f        5 hours ago         415.2 MB
mysql                     latest              2dd01afbe8df        18 hours ago        485.5 MB
centos/mysql-57-centos7   latest              b996585055be        2 weeks ago         448.1 MB
centos                    latest              75835a67d134        2 weeks ago         200.4 MB
[root@itpux ~]# 

 

posted on 2018-10-26 01:02  luoxf  阅读(212)  评论(0)    收藏  举报

导航