尽量简洁
下载 mysql 镜像
docker pull mysql
编写 docker-compose.yml
为了避免每次都要输入冗长的docker run ...
命令,我们使用 docker-compose.yml
来保存下来,以后只需要 docker-compose up
即可启用
docker-compose.yml 文件:
version: "2"
services:
mysqldb:
container_name: "docker-db1"
image: "mysql"
volumes:
- "/Users/Kron/docker-DB/conf.d/docker-db1:/etc/mysql/conf.d"
- "/Users/Kron/docker-DB/mysql/docker-db1:/var/lib/mysql"
environment:
- MYSQL_ROOT_PASSWORD=xxxx
- MYSQL_DATABASE=app
- MYSQL_USER=xxxx
- MYSQL_PASSWORD=xxxx
启动
docker-compose up -d # Detached mode: Run containers in the background