关于docker:Docker-安装-Mysql-57

41次阅读

共计 3240 个字符,预计需要花费 9 分钟才能阅读完成。

查找镜像

查找镜像的形式如下:

[zxd@localhost seata]$ docker search mysql
NAME                            DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql                           MySQL is a widely used, open-source relation…   13614     [OK]       
mariadb                         MariaDB Server is a high performing open sou…   5197      [OK]       
phpmyadmin                      phpMyAdmin - A web interface for MySQL and M…   713       [OK]       
percona                         Percona Server is a fork of the MySQL relati…   597       [OK]       
bitnami/mysql                   Bitnami MySQL Docker Image                      80                   [OK]
databack/mysql-backup           Back up mysql databases to... anywhere!         77                   
linuxserver/mysql-workbench                                                     45                   
ubuntu/mysql                    MySQL open source fast, stable, multi-thread…   40                   
linuxserver/mysql               A Mysql container, brought to you by LinuxSe…   38                   
circleci/mysql                  MySQL is a widely used, open-source relation…   28                   
google/mysql                    MySQL server for Google Compute Engine          22                   [OK]
rapidfort/mysql                 RapidFort optimized, hardened image for MySQL   13                   
bitnami/mysqld-exporter                                                         4                    
ibmcom/mysql-s390x              Docker image for mysql-s390x                    2                    
vitess/mysqlctld                vitess/mysqlctld                                1                    [OK]
newrelic/mysql-plugin           New Relic Plugin for monitoring MySQL databa…   1                    [OK]
hashicorp/mysql-portworx-demo                                                   0                    
rapidfort/mysql-official        RapidFort optimized, hardened image for MySQ…   0                    
docksal/mysql                   MySQL service images for Docksal - https://d…   0                    
mirantis/mysql                                                                  0                    
rapidfort/mysql8-ib             RapidFort optimized, hardened image for MySQ…   0                    
cimg/mysql                                                                      0                    
eclipse/mysql                   Mysql 5.7, curl, rsync                          0                    [OK]
drud/mysql                                                                      0                    
silintl/mysql-backup-restore    Simple docker image to perform mysql backups…   0                    [OK]

获取镜像

docker 能够应用上面的命令获取镜像:

docker pull mysql:5.7

查找镜像

能够应用上面的命令获取以后下载的所有镜像:

docker images

集体获取到的镜像内容如下:

[zxd@localhost seata]$ docker images
REPOSITORY                          TAG       IMAGE ID       CREATED         SIZE
redis                               latest    0256c63af7db   5 days ago      117MB
mysql                               5.7       d410f4167eea   2 weeks ago     495MB
redis                               <none>    3e12e2ceb68f   2 weeks ago     117MB
apache/rocketmq                     4.9.4     a2a50ca263c3   5 months ago    548MB
apacherocketmq/rocketmq-dashboard   latest    eae6c5db5d11   14 months ago   738MB
hello-world                         latest    feb5d9fea6a5   15 months ago   13.3kB

本地创立 mysql 的映射目录

在正式的启动 Mysql 镜像之前进行映射目录的配置。

mkdir -p /opt/mysql/data /opt/mysql/logs /opt/mysql/conf

/root/mysql/conf 中创立 *.cnf 文件(叫什么都行)。这里以集体创立的 mysql.conf 为例:

touch mysql.conf

创立容器,将数据,日志, 配置文件映射到本机,留神这里的 root 明码为 root:

docker run -p 13306:3306 --name mysql -v /opt/mysql/conf:/etc/mysql/conf.d -v /opt/mysql/logs:/logs -v /opt/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7

运行之后,咱们执行 docker ps 查看以后运行的 mysql 镜像:

[zxd@localhost conf]$ docker ps
CONTAINER ID   IMAGE                   COMMAND                  CREATED              STATUS              PORTS                                                                                                               NAMES
e95a0bc7b4a4   mysql:5.7               "docker-entrypoint.s…"   About a minute ago   Up About a minute   33060/tcp, 0.0.0.0:13306->3306/tcp, :::13306->3306/tcp                                                              mysql

相干运行参数如下:

-d: 后盾运行容器
-p 将容器的端口映射到本机的端口
-v 将主机目录挂载到容器的目录
-e 设置参数

运行之后咱们执行上面的命令查看:

[zxd@localhost conf]$ mysql -uroot -proot -P 13306
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.6.51 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, 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> 

最初查看 /opt/mysql/data 目录是否有数据文件:

[zxd@localhost conf]$ sudo ls /opt/mysql/data
auto.cnf    client-cert.pem  ibdata1      ibtmp1      performance_schema  server-cert.pem
ca-key.pem  client-key.pem   ib_logfile0  mysql       private_key.pem      server-key.pem
ca.pem        ib_buffer_pool   ib_logfile1  mysql.sock  public_key.pem      sys

运行容器

docker run -p 13306:3306 --name mysql57 --restart=always -v /opt/mysql/conf:/etc/mysql/conf.d -v /opt/mysql/logs:/logs -v /opt/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7

正文完
 0