您现在的位置是:首页 > 文章详情

docker安装mysql

日期:2018-11-04点击:619

从阿里云的Docker Hub 上pull一个MySQL的image.
docker pull registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql:5.7

查看下载镜像
[root@hcdev yum.repos.d]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql 5.7 ec7e75e5260c 2 years ago 360MB

名字太长,修改为短的tag
[root@hcdev yum.repos.d]# docker tag registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql:5.7 mysql:5.7
[root@hcdev yum.repos.d]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 ec7e75e5260c 2 years ago 360MB
registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql 5.7 ec7e75e5260c 2 years ago 360MB

根据镜像创建容器
[root@hcdev yum.repos.d]# docker create -it mysql:5.7
d625d3596ca386e57b047f7e4a50c78ba9330eb094a9ff6afd83a9daa02efd9c

启动MySQL容器
[root@hcdev yum.repos.d]# docker run --name mtmysql -e MYSQL_ROOT_PASSWORD=chengce243 -d -i -p 3306:3306 mysql:5.7
5437d787164bf7174c71a64501151ed2132d030999a37a11c94fba13afcc8a36
[root@hcdev yum.repos.d]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5437d787164b mysql:5.7 "/entrypoint.sh mysq…" 8 seconds ago Up 7 seconds 0.0.0.0:3306->3306/tcp mtmysql

进入MySQL终端
docker exec -it mtmysql mysql -uroot -pchengce243

也可以
docker exec -it 5437d787164b mysql -uroot -pchengce243

MySQL停止
docker stop mtmysql

也可以
docker stop 5437d787164b

MySQL启动
docker start mtmysql

也可以
docker start 5437d787164b

原文链接:https://yq.aliyun.com/articles/664615
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章