安装docker
yum -y install docker
systemctl start docker
systemctl status docker
systemctl enable docker
docker version
docker info
安装MySQL
查询mysql:
docker search mysql
查看镜像:
docker images
拉取mysql5.7版本:
docker pull mysql:5.7
方式一:直接运行镜像:
docker run -d --name mysql5.7 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7
方式二:持久化运行镜像:
mkdir mysql_docker
cd mysql_docker/
echo $PWD
docker run --name mysqlserver -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d -i -p 3306:3306 mysql:5.7
进入mysql容器,并登陆mysql
docker exec -it mysqlserver bash
mysql -uroot -p
开启远程访问权限:
use mysql;
select host,user from user;
grant all privileges on *.* to root@'%' identified by "123456";
flush privileges;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
flush privileges;
关闭docker中mysql容器
docker stop mysqlserver
查看docker日志:
docker logs -f --tail 10 a4dac74d48f7 (即:CONTAINER ID)