查找Docker Hub上的mysql镜像
runoob@runoob:/mysql$ docker search mysqlNAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relati... 2529 [OK] mysql/mysql-server Optimized MySQL Server Docker images. Crea... 161 [OK]centurylink/mysql Image containing mysql. Optimized to be li... 45 [OK]sameersbn/mysql 36 [OK]google/mysql MySQL server for Google Compute Engine 16 [OK]appcontainers/mysql Centos/Debian Based Customizable MySQL Con... 8 [OK]marvambass/mysql MySQL Server based on Ubuntu 14.04 6 [OK]drupaldocker/mysql MySQL for Drupal 2 [OK]azukiapp/mysql Docker image to run MySQL by Azuki - http:... 2 [OK]...
这里我们拉取官方的镜像,标签为5.6
runoob@runoob:~/mysql$ docker pull mysql:5.6等待下载完成后,我们就可以在本地镜像列表里查到REPOSITORY为mysql,标签为5.6的镜像。
runoob@runoob:~/mysql$ docker images |grep mysqlmysql 5.6 2c0964ec182a 3 weeks ago 329 MB
使用mysql镜像
运行容器
runoob@runoob:~/mysql$ 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:5.621cb89213c93d805c5bacf1028a0da7b5c5852761ba81327e6b99bb3ea89930erunoob@runoob:~/mysql$命令说明:
-p 3306:3306:将容器的 3306 端口映射到主机的 3306 端口。
-v -v $PWD/conf:/etc/mysql/conf.d:将主机当前目录下的 conf/my.cnf 挂载到容器的 /etc/mysql/my.cnf。
-v $PWD/logs:/logs:将主机当前目录下的 logs 目录挂载到容器的 /logs。
-v $PWD/data:/var/lib/mysql :将主机当前目录下的data目录挂载到容器的 /var/lib/mysql 。
-e MYSQL_ROOT_PASSWORD=123456:初始化 root 用户的密码。
查看容器启动情况
runoob@runoob:~/mysql$ docker psCONTAINER ID IMAGE COMMAND ... PORTS NAMES21cb89213c93 mysql:5.6 "docker-entrypoint.sh" ... 0.0.0.0:3306->3306/tcp mymysql
发表评论