1.查看所有的dcker hub上的mysql镜像 docker search mysql
MacBook:mysql_docker max$ docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 6465 [OK]
mariadb MariaDB is a community-developed fork of MyS… 2034 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 471 [OK]
percona Percona Server is a fork of the MySQL relati… 344 [OK]
zabbix/zabbix-server-mysql Zabbix Server with MySQL database support 106 [OK]
hypriot/rpi-mysql RPi-compatible Docker Image with Mysql 88
centurylink/mysql Image containing mysql. Optimized to be link… 60 [OK]
zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server wi… 57 [OK]
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 36 [OK]
tutum/mysql Base docker image to run a MySQL database se… 32
centos/mysql-57-centos7 MySQL 5.7 SQL database server 31
mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr… 30
schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic backup… 20 [OK]
zabbix/zabbix-proxy-mysql Zabbix proxy with MySQL database support 15 [OK]
bitnami/mysql Bitnami MySQL Docker Image 15 [OK]
linuxserver/mysql A Mysql container, brought to you by LinuxSe… 14
centos/mysql-56-centos7 MySQL 5.6 SQL database server 8
openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 image… 6
circleci/mysql MySQL is a widely used, open-source relation… 5
dsteinkopf/backup-all-mysql backup all DBs in a mysql server 4 [OK]
mysql/mysql-router MySQL Router provides transparent routing be… 2
openzipkin/zipkin-mysql Mirror of https://quay.io/repository/openzip… 1
cloudfoundry/cf-mysql-ci Image used in CI of cf-mysql-release 0
cloudposse/mysql Improved `mysql` service with support for `m… 0 [OK]
ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 0 [OK]
2.选择需要拉取的镜像docker pull mysql,会默认拉取tag为latest的mysql官方镜像
latest: Pulling from library/mysql
683abbb4ea60: Pull complete
0550d17aeefa: Pull complete
7e26605ddd77: Pull complete
9882737bd15f: Pull complete
999c06ab75f6: Pull complete
c71d695f9937: Pull complete
c38f847c1491: Pull complete
5e0cb05a8fc3: Pull complete
c89e3e373fca: Pull complete
fa39a2c9922d: Pull complete
b293d9c897c4: Pull complete
3dc061869740: Pull complete
Digest: sha256:43ed4f8c9d1695e97a39cdfe9475af9096e3723cfb79d820d8da00d61a277a85
Status: Downloaded newer image for mysql:latest
3.新建本地映射到docker镜像的mysql文件目录,/mysql/conf、/mysql/logs、/mysql/data。完毕后使用
docker run -p 3306:3306 --name mymysql -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql
4.完成后,使用docker ps即可查看正在运行的容器
MacBook:mysql max$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b158184523be mysql "docker-entrypoint.s…" 13 seconds ago Up 26 seconds 0.0.0.0:3306->3306/tcp mymysql
5.进入docker 内部
MacBook:mysql max$ docker exec -it b158184523be bash
root@b158184523be:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.11 MySQL Community Server - GPL
Copyright (c) 2000, 2018, 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>