第一步:安装docker
brew cask install docker
docker教程
docker安装mysql
第二步:宿主机子新建数据目录
mkdir -p ~/mysql/data
第三步:安装镜像并完成配置
docker run -p 3309:3306 --name mymysql -v ~/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
命令解释
Last login: Tue Apr 30 00:18:34 on ttys002
huhuhuhrdeMacBook-Pro:~ huorong$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d668afeac572 mysql:5.7 "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 33060/tcp, 0.0.0.0:3309->3306/tcp mymysql
huhuhuhrdeMacBook-Pro:~ huorong$
-p 宿主3309映射到3306
--name 镜像名称mymysql
宿主路径: ~/mysql/data
docker机:/var/lib/mysql
密码: 123456
停止mysql:
docker stop d668afeac572
启动mysql:
docker start d668afeac572
查看运行中镜像:
docker ps
查看docker安装的目录:
docker images