修改系统时间
[root@32c64- ~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
或者
[root@32c64- ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
或者
[root@32c64- ~]# systemctl enable ntpd
[root@32c64- ~]# systemctl start ntpd
或者
[root@32c64- ~]# timedatactl set-timezone Asia/Shanghai 若想改回UTC时间 删除/etc/localtime便可
查询镜像
[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... [OK]
docker.io docker.io/mariadb MariaDB is a community-developed fork of M... [OK]
docker.io docker.io/mysql/mysql-server Optimized MySQL Server Docker images. Crea... [OK]
docker.io docker.io/zabbix/zabbix-server-mysql Zabbix Server with MySQL database support [OK]
docker.io docker.io/hypriot/rpi-mysql RPi-compatible Docker Image with Mysql
docker.io docker.io/zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server ... [OK]
docker.io docker.io/centurylink/mysql Image containing mysql. Optimized to be li... [OK]
docker.io docker.io/1and1internet/ubuntu--nginx-php-phpmyadmin-mysql- ubuntu--nginx-php-phpmyadmin-mysql- [OK]
docker.io docker.io/centos/mysql--centos7 MySQL 5.7 SQL database server
docker.io docker.io/mysql/mysql-cluster Experimental MySQL Cluster Docker images. ...
docker.io docker.io/tutum/mysql Base docker image to run a MySQL database ...
docker.io docker.io/schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic back... [OK]
docker.io docker.io/bitnami/mysql Bitnami MySQL Docker Image [OK]
docker.io docker.io/zabbix/zabbix-proxy-mysql Zabbix proxy with MySQL database support [OK]
docker.io docker.io/linuxserver/mysql A Mysql container, brought to you by Linux...
docker.io docker.io/centos/mysql--centos7 MySQL 5.6 SQL database server
docker.io docker.io/circleci/mysql MySQL is a widely used, open-source relati...
docker.io docker.io/mysql/mysql-router MySQL Router provides transparent routing ...
docker.io docker.io/openshift/mysql--centos7 DEPRECATED: A Centos7 based MySQL v5. ima...
docker.io docker.io/dsteinkopf/backup-all-mysql backup all DBs in a mysql server [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...
docker.io docker.io/ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL [OK]
docker.io docker.io/cloudfoundry/cf-mysql-ci Image used in CI of cf-mysql-release
docker.io docker.io/cloudposse/mysql Improved `mysql` service with support for ... [OK]
下载镜像
//如果需要挂载以前的数据,注意下载和以前对应的版本
[root@bms-e4e3 ~]# docker inspect 旧版本镜像id
[root@bms-e4e3 ~]# docker pull mysql:5.7
运行镜像
docker run -p : --name mysql5. --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= -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. bash
root@b6ab4d9b2869:/# date
Fri May :: CST
//如果时间不正确,则做以下操作
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.
//再次进入容器查看容器时间和mysql时间
[root@mysql ~]# docker exec -it mysql5. bash
root@b6ab4d9b2869:/# date
Fri May :: CST
root@b6ab4d9b2869:/# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7.-log MySQL Community Server (GPL) Copyright (c) , , 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() |
+---------------------+
| -- :: |
+---------------------+
row in set (0.00 sec) mysql>