使用Docker部署MySQL作为测试环境

使用Docker部署MySQL作为测试环境

这里说明了作为测试环境,生产环境下不建议将MySQL使用Docker部署

查找镜像

root@centos7-docker opt]# docker search mysql NAME                           DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED mysql                          MySQL is a widely used, open-source relation…   12527     [OK]        mariadb                        MariaDB Server is a high performing open sou…   4819      [OK]        percona                        Percona Server is a fork of the MySQL relati…   575       [OK]        phpmyadmin                     phpMyAdmin - A web interface for MySQL and M…   527       [OK]        bitnami/mysql                  Bitnami MySQL Docker Image                      70                   [OK] linuxserver/mysql-workbench                                                    36                    linuxserver/mysql              A Mysql container, brought to you by LinuxSe…   35                    ubuntu/mysql                   MySQL open source fast, stable, multi-thread…   31                    circleci/mysql                 MySQL is a widely used, open-source relation…   25                    google/mysql                   MySQL server for Google Compute Engine          21                   [OK] vmware/harbor-db               Mysql container for Harbor                      10                    bitnami/mysqld-exporter                                                        3                     ibmcom/mysql-s390x             Docker image for mysql-s390x                    2                     newrelic/mysql-plugin          New Relic Plugin for monitoring MySQL databa…   1                    [OK] vitess/mysqlctld               vitess/mysqlctld                                1                    [OK] nasqueron/mysql                                                                1                    [OK] cimg/mysql                                                                     0                     silintl/mysql-backup-restore   Simple docker image to perform mysql backups…   0                    [OK] drud/mysql-local-57            ddev mysql local container                      0                     drud/mysql                                                                     0                     drud/mysql-docker-local-57     This repo has been deprecated, new tags are …   0                     drud/mysql-docker-local        docker containers for local womysql rk          0                    [OK] docksal/mysql                  MySQL service images for Docksal - https://d…   0                     mirantis/mysql                                                                 0                     drud/mysqld-exporter                                                           0          

建立目录映射

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

运行

docker run -p 3306:3306 --name zsdmysql02 \ -v /opt/docker/mysql/conf:/etc/mysql \ -v /opt/docker/mysql/logs:/var/log/mysql \ -v /opt/docker/mysql/data:/var/lib/mysql \ -e MYSQL_ROOT_PASSWORD=123456 \ -d mysql 

查看看数据目录映射为主机的目录