docker之服务搭建
使用docker搭建相关服务:
1. MySQL服务
1) 拉取镜像
docker pull mysql:5.7 # 拉取 mysql 5.7 docker pull mysql # 拉取最新版mysql镜像 # 不指定版本,默认拉取最新的
2)启动服务
sudo docker run -p 3306:3306 --name mysql -v /usr/local/docker/mysql/conf:/etc/mysql -v /usr/local/docker/mysql/logs:/var/log/mysql -v /usr/local/docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7 –name:容器名,此处命名为mysql -e:配置信息,此处配置mysql的root用户的登陆密码 -p:端口映射,此处映射 主机3306端口 到 容器的3306端口 -v: 挂载数据卷, 宿主目录: 容器目录 -d:源镜像名,此处为 mysql:5.7
3) 如果你的容器运行正常,但是无法访问到MySQL,一般有以下几个可能的原因:
a) 防火墙
# 开放端口: $ systemctl status firewalld $ firewall-cmd --zone=public --add-port=3306/tcp -permanent $ firewall-cmd --reload # 关闭防火墙: $ sudo systemctl stop firewalld
b)需要进入docker本地客户端设置远程访问账号
$ sudo docker exec -it mysql bash $ mysql -uroot -p123456 mysql> grant all privileges on *.* to ‘%‘ identified by "password";
# mysql使用mysql数据库中的user表来管理权限,修改user表就可以修改权限(只有root账号可以修改) mysql> use mysql; Database changed mysql> select host,user,password from user; +--------------+------+-------------------------------------------+ | host | user | password | +--------------+------+-------------------------------------------+ | localhost | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E | | 192.168.1.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E | +--------------+------+-------------------------------------------+ 2 rows in set (0.00 sec) mysql> grant all privileges on *.* to ‘%‘ identified by "password"; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> select host,user,password from user; +--------------+------+-------------------------------------------+ | host | user | password | +--------------+------+-------------------------------------------+ | localhost | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E | | 192.168.1.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E | | % | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E | +--------------+------+-------------------------------------------+ 3 rows in set (0.00 sec)
相关推荐
王道革 2020-11-25
bwyyziq 2020-11-22
pigsmall 2020-11-19
changecan 2020-11-19
helloWorldAndYou 2020-11-16
nginxs 2020-11-14
红石丶 2020-11-13
WanKaShing 2020-11-12
yangkang 2020-11-12
滴水穿石点石成金 2020-11-12
张荣珍 2020-11-12
wuxunanjing 2020-11-11
魅惑青花瓷 2020-11-11
lihongtai 2020-11-09
yangkang 2020-11-09
worldsnow 2020-11-06
MichaelJScofield 2020-11-06
TaoTaoFu 2020-11-06