docker 创建mysql镜像,并成功进行远程连接
1.安装
1.1 拉取镜像
docker pull mysql
拉取成功可以验证一下
docker images
1.2 创建并启动一个mysql容器
docker run --name ly-mysql -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -d mysql
- –name:给新创建的容器命名,此处命名为ly-mysql
- -e:配置信息,此处配置mysql的root用户的登陆密码
- -p:端口映射,此处映射主机3306端口到容器pwc-mysql的3306端口
- -d:成功启动容器后输出容器的完整ID.
- 最后一个mysql指的是mysql镜像名字
到这里我们查看容器运行状态:
$ sudo docker ps
可以看到容器的简写ID,容器的源镜像,创建时间,状态,端口映射信息,容器名字等。
1.3 连接测试
使用navicat远程连接,这里碰到几个问题
1.3.1 mysql连接IP问题
首先这个IP肯定不是localhost,然后以为是mysql容器的IP
1.3.1.1 查看mysql容器的ip
docker inspect --format '{{ .NetworkSettings.IPAddress }}' <container-ID>
结果是:172.17.0.2
但是还是连接不上
1.3.1.2 获取docker主机 IP
docker-machine ip
192.168.99.100
这个可以连接
结论:
当使用windows和macOS时,不应该使用localhost而应该使用docker-machine ip
1.3.2 连接mysql 8提示2059 - authentication plugin 'caching_sha2_password...
原因:由于myslq8不支持动态修改密码验证方式
解决方案:
- 进入mysql容器
docker exec -it ly-mysql bash
- 连接mysql
mysql -uroot -p
3.修改配置
use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new password';
FLUSH PRIVILEGES;
1.4 其他
1.4.1 记录几个命令
1.4.1.1 退出容器
- 如果要正常退出不关闭容器,请按Ctrl+P+Q进行退出容器
- 如果使用exit退出,那么在退出之后会关闭容器,可以使用下面的流程进行恢复
使用docker restart命令重启容器
使用docker attach命令进入容器
1.4.1.2 修改MySQL配置文件有两种方法:
- 一是进入容器,修改容器里的MySQL的配置文件,然后重新启动容器,例如:
$ sudo docker exec -it ly-mysql /usr/bin/bash
然后可以进入容器的命令行模式,接着修改 /etc/mysql/my.cnf 文件即可
- 二是挂载主机的mysql配置文件,官方文档如下:
The MySQL startup configuration is specified in the file /etc/mysql/my.cnf, and that file in turn includes any files found in the /etc/mysql/conf.d directory that end with .cnf. Settings in files in this directory will augment and/or override settings in /etc/mysql/my.cnf. If you want to use a customized MySQL configuration, you can create your alternative configuration file in a directory on the host machine and then mount that directory location as /etc/mysql/conf.d inside the mysql container.
If /my/custom/config-file.cnf is the path and name of your custom configuration file, you can start your mysql container like this (note that only the directory path of the custom config file is used in this command):
$ docker run --name some-mysql -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
This will start a new container some-mysql where the MySQL instance uses the combined startup settings from /etc/mysql/my.cnf and /etc/mysql/conf.d/config-file.cnf, with settings from the latter taking precedence.
docker 创建mysql镜像,并成功进行远程连接的更多相关文章
- docker构建mysql容器及Navicat 远程连接
1. MySQL部署 1.1拉取MySQL镜像 docker pull mysql 查看镜像 docker images 1.2创建MySQL容器 首先建立所需要的 文件夹: docker run - ...
- Docker创建mysql镜像
原文: https://blog.csdn.net/uk8692/article/details/49386679 https://blog.csdn.net/qq362228416/article/ ...
- 使用docker制作Mysql镜像
一.过程说明 通过Dockerfile创建mysql镜像,使用的mysql软件包为mariadb二进制分发版,最终在宿主机启动mysql容器从而能在mysql容器外部访问mysql服务. 宿主机IP ...
- Docker创建MySQL集装箱
原文链接:Docker创建MySQL集装箱 这样做的目的是创建一个MySQL的image,出来的容器里自己主动启动MySQL服务接受外部连接 步骤: 1. 首先创建一个文件夹并在文件夹下创建一个Doc ...
- [修]开启MySQL远程访问权限 允许远程连接
原文地址:http://www.cnblogs.com/XL-Liang/archive/2012/05/03/2481310.html 这个地址也许更有帮助:http://www.cppblog.c ...
- 开启MySQL远程访问权限 允许远程连接
1.登陆mysql数据库 mysql -u root -p 查看user表 mysql> use mysql;Database changedmysql> select host,user ...
- Docker安装mysql镜像并进行主从配置
Docker安装mysql镜像并进行主从配置 1.下载需要的mysql版本镜像 docker pull mysql:5.6 2.启动mysql服务实例(基本启动) #启动主mysql docker r ...
- MacOS使用Docker创建MySQL主主数据库
主从同步配置可以参考上一篇MacOS使用Docker创建MySQL主从数据库 一.创建MySQL数据库容器配置文件对应目录 我们在当前用户下创建一组目录,用来存放MySQL容器配置文件,(Linux下 ...
- docker 生成mysql镜像启动时自动执行sql
文章转载自:https://www.jianshu.com/p/12fc253fa37d 在docker 创建 mysql 容器时,往往需要在创建容器的过程中创建database 实例,代码如下: # ...
随机推荐
- App间相互跳转及图片分享
A-app: Info--URL Types--URL Schemes:A-app(一个标识,允许别的app调用本App) info.plist 添加白名单: LSApplicationQueries ...
- node05
1.ejs: const ejs = require('ejs') ejs.renderFile('./template/a.ejs', {name:'cc'}, function (err, dat ...
- tyflow车撞墙测试
- 929. Unique Email Addresses
929. Unique Email Addresses Easy 22766FavoriteShare Every email consists of a local name and a domai ...
- Oracle 查询表空间使用情况
select * from (Select a.tablespace_name, to_char(a.bytes / 1024 / 1024, '99,999.999 ...
- 元组Tuple的使用
在方法中有多个值返回,返回值封装成对象又不方便,可以用 out 返回或ref返回, 这里介绍元组,也可以作为多个返回值的使用,最多携带8个返回值 Task.Factory.StartNew<Tu ...
- javascript 省市区三级联动 附: json数据
html: <label> <span>购买地址</span> <select name="PurchaseProvince" style ...
- [Swift]LeetCode244.最短单词距离 II $ Shortest Word Distance II
This is a follow up of Shortest Word Distance. The only difference is now you are given the list of ...
- [Swift]LeetCode877. 石子游戏 | Stone Game
Alex and Lee play a game with piles of stones. There are an even number of piles arranged in a row, ...
- hive中beeline取回数据的完整流程
这里我们从BeeLine.execute讲起. 接下来来到BeeLine.dispatch,这里的入参就是sql语句.方法的最后调用了Commands.sql,然后调用到了Commands.execu ...