此处拿mysql5.7作为示范
docker pull mysql:5.7 5.7: Pulling from library/mysql f003217c5aae: Already exists 65d94f01a09f: Already exists 43d78aaa6078: Already exists a0f91ffbdf69: Already exists 59ee9e07e12f: Already exists 04d82978082c: Already exists 70f46ebb971a: Already exists ba61822c65c2: Pull complete dec59acdf78a: Pull complete 0a05235a6981: Pull complete c87d621d6916: Pull complete Digest: sha256:1a73b6a8f507639a8f91ed01ace28965f4f74bb62a9d9b9e7378d5f07fab79dc Status: Downloaded newer image for mysql:5.7 docker.io/library/mysql:5.7
docker run -d -p 3306:3306 -v E:\dockerWorkspace\mysql5.7\conf:/etc/mysql/conf.d -v E:\dockerWorkspace\mysql5.7\data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root --name mysql57 mysql:5.7 # 参数解析 -d 后台运行 -v 挂载卷 主机目录:容器目录 可挂载多个卷 -e 设置参数 此处设置MYSQL初始密码 --name 设置容器名称
docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 340468efcecf mysql:5.7 "docker-entrypoint.s…" 5 minutes ago Up 5 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp mysql57