docker+mysql基本搭建过程,及修改时间

我们两清 提交于 2021-02-11 13:08:01

修改系统时间

[root@32c64-0425445 ~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
或者
[root@32c64-0425445 ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
或者
[root@32c64-0425445 ~]# systemctl enable ntpd
[root@32c64-0425445 ~]# systemctl start ntpd

 

查询镜像

[root@bms-e4e3 ~]# docker search mysql
INDEX       NAME                                                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/mysql                                                  MySQL is a widely used, open-source relati...   7708      [OK]       
docker.io   docker.io/mariadb                                                MariaDB is a community-developed fork of M...   2530      [OK]       
docker.io   docker.io/mysql/mysql-server                                     Optimized MySQL Server Docker images. Crea...   585                  [OK]
docker.io   docker.io/zabbix/zabbix-server-mysql                             Zabbix Server with MySQL database support       161                  [OK]
docker.io   docker.io/hypriot/rpi-mysql                                      RPi-compatible Docker Image with Mysql          103                  
docker.io   docker.io/zabbix/zabbix-web-nginx-mysql                          Zabbix frontend based on Nginx web-server ...   86                   [OK]
docker.io   docker.io/centurylink/mysql                                      Image containing mysql. Optimized to be li...   60                   [OK]
docker.io   docker.io/1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5   ubuntu-16-nginx-php-phpmyadmin-mysql-5          48                   [OK]
docker.io   docker.io/centos/mysql-57-centos7                                MySQL 5.7 SQL database server                   45                   
docker.io   docker.io/mysql/mysql-cluster                                    Experimental MySQL Cluster Docker images. ...   39                   
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...   24                   [OK]
docker.io   docker.io/bitnami/mysql                                          Bitnami MySQL Docker Image                      23                   [OK]
docker.io   docker.io/zabbix/zabbix-proxy-mysql                              Zabbix proxy with MySQL database support        20                   [OK]
docker.io   docker.io/linuxserver/mysql                                      A Mysql container, brought to you by Linux...   18                   
docker.io   docker.io/centos/mysql-56-centos7                                MySQL 5.6 SQL database server                   12                   
docker.io   docker.io/circleci/mysql                                         MySQL is a widely used, open-source relati...   9                    
docker.io   docker.io/mysql/mysql-router                                     MySQL Router provides transparent routing ...   8                    
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/openzipkin/zipkin-mysql                                Mirror of https://quay.io/repository/openz...   2                    
docker.io   docker.io/jelastic/mysql                                         An image of the MySQL database server main...   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]

下载镜像

//如果需要挂载以前的数据,注意下载和以前对应的版本
[root@bms-e4e3 ~]# docker inspect 旧版本镜像id
[root@bms-e4e3 ~]# docker pull mysql:5.7

 

运行镜像

docker run -p 3306:3306 --name mysql5.7 --restart=always -v /data/mysql/datadir:/var/lib/mysql -v /data/mysql/conf/:/etc/mysql/ -v /data/mysql/log/:/var/log/mysql/ -e MYSQL_ROOT_PASSWORD=123456 -d docker.io/mysql:5.7

 

 

命令说明:
-p 3306:3306:将容器的3306端口映射到主机的3306端口
-v $PWD/conf/my.cnf:/etc/mysql/my.cnf:将主机当前目录下的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用户的密码

 

查看容器时间

[root@mysql ~]# docker exec -it mysql5.7 bash
root@b6ab4d9b2869:/# date
Fri May 17 11:21:57 CST 2019
//如果时间不正确,则做以下操作
root@b6ab4d9b2869:/# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
或者
root@b6ab4d9b2869:/# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

root@b6ab4d9b2869:/# exit

//重启mysql容器
[root@mysql ~]# docker restart mysql5.7
//再次进入容器查看容器时间和mysql时间
[root@mysql ~]# docker exec -it mysql5.7 bash
root@b6ab4d9b2869:/# date
Fri May 17 11:26:01 CST 2019
root@b6ab4d9b2869:/# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 26
Server version: 5.7.26-log MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> select now();
+---------------------+
| now()               |
+---------------------+
| 2019-05-17 11:25:06 |
+---------------------+
1 row in set (0.00 sec)

mysql>

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!