Docker 本地安装 mysql 数据库

Docker: Accelerated Container Application Development

下载对应操作系统版本的 docker ;并安装。

基础操作不再赘述。

打开 macOS 终端,开始 docker 安装mysql之旅

第一步

docker search mysql

复制代码
》〉docker search mysql
NAME                   DESCRIPTION                                      STARS     OFFICIAL
mysql                  MySQL is a widely used, open-source relation...   15813     [OK]
bitnami/mysql          Bitnami container image for MySQL                135       
circleci/mysql         MySQL is a widely used, open-source relation...   31        
bitnamicharts/mysql    Bitnami Helm chart for MySQL                     0         
cimg/mysql                                                              3         
ubuntu/mysql           MySQL open source fast, stable, multi-thread...   68        
google/mysql           MySQL server for Google Compute Engine           26        
linuxserver/mysql      A Mysql container, brought to you by LinuxSe...   44        
elestio/mysql          Mysql, verified and packaged by Elestio          1         
docksal/mysql          MySQL service images for Docksal - https://d...   0         
alpine/mysql           mysql client                                     4         
datajoint/mysql        MySQL image pre-configured to work smoothly ...   2         
ilios/mysql            Mysql configured for running Ilios               1         
ddev/mysql             ARM64 base images for ddev-dbserver-mysql-8....   1         
mirantis/mysql                                                          0         
corpusops/mysql        https://github.com/corpusops/docker-images/      0         
mysql/mysql-server     Optimized MySQL Server Docker images. Create...   1030      
vulhub/mysql                                                            1         
cbioportal/mysql       This repository hosts MySQL database images ...   1         
vitess/mysql           Lightweight image to run MySQL with Vitess       1         
mysql/mysql-router     MySQL Router provides transparent routing be...   28        
mysql/mysql-cluster    Experimental MySQL Cluster Docker images. Cr...   100       
nasqueron/mysql                                                         1         
mysql/mysql-operator   MySQL Operator for Kubernetes                    1         
openeuler/mysql                                                         0    

选择 STARS 最高的,mysql ;并且安装最新版本 。

第二步

docker pull mysql:latest

复制代码
》〉docker pull mysql:latest
latest: Pulling from library/mysql
9845df06f911: Pull complete 
4bd1fb59dd90: Pull complete 
d23320eed97a: Pull complete 
7074f55c9a02: Pull complete 
72ac912b8a2e: Pull complete 
b097427f1ebe: Pull complete 
b288ccce2510: Pull complete 
7488ffd7127f: Pull complete 
8a50ff4ab30c: Pull complete 
5056ce4ab875: Pull complete 
Digest: sha256:04768cb63395f56140b4e92cad7c8d9f48dfa181075316e955da75aadca8a7cd
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest

Docker 图形界面工具,也能看到 mysql 已经被安装。

第三步

docker images

查看,Docker 中的 images 镜像文件列表:

复制代码
》〉docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
mysql        latest    edbdd97bf78b   7 weeks ago   859MB

当前仅有一个。

第四步

docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql

复制代码
>>docker ps 
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                         NAMES
d20e4d330be2   mysql     "docker-entrypoint.s..."   8 minutes ago   Up 8 minutes   0.0.0.0:3306->3306/tcp, [::]:3306->3306/tcp   mysql-test

第五步

docker exec -it mysql-test bash

登录容器。