准备工作
- 设置镜像源,下载镜像更快
- 创建所需映射出的目录
- /Users/peak6/Documents/DockerData/mysql/conf:存mysql的配置文件
- /Users/peak6/Documents/DockerData/mysql/data:存储表数据
- /Users/peak6/Documents/DockerData/mysql/logs:存储mysql日志
开始安装
- 拉取镜像
docker pull mysql
- 查看镜像id,找到mysql的镜像id
docker images
- 运行docker容器
docker run -p 3306:3306 --name mysql -v /Users/peak6/Documents/DockerData/mysql/conf:/etc/mysql/conf.d -v /Users/peak6/Documents/DockerData/mysql/data:/var/lib/mysql -v /Users/peak6/Documents/DockerData/mysql/logs:/logs -e MYSQL_ROOT_PASSWORD=123456 -d 镜像id
- 设置自启动
docker update --restart=always mysql
同理安装redis
docker run -p 6379:6379 --name redis -v /Users/peak6/Documents/DockerData/redis/conf/redis.conf:/etc/redis/redis.conf -v /Users/peak6/Documents/DockerData/redis/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes