ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

Centos7 Docker离线部署Mysql5.7

2021-01-17 16:33:13  阅读:264  来源: 互联网

标签:kB Loading MB 离线 Centos7 mysql Docker root docker


1 环境信息

查看系统内核

[root@localhost /]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)

2 虚拟机拉取镜像

此处资源获取在虚拟机中进行,完成后上传到服务器安装

2.1 拉取mysql5.7镜像

[root@localhost /]# docker pull mysql:5.7

2.2 导出镜像

[root@localhost /]# docker save -o /opt/module/software/jingxiang/mysql57.tar mysql:5.7

3 服务器加载镜像

将提供的docker文件夹上传到服务器的 /opt/module/software/jingxiang 目录下

3.1 导入Mysql镜像

[root@localhost /]# docker load -i /opt/module/software/jingxiang/mysql57.tar
99b5261d397c: Loading layer [==================================================>] 58.51 MB/58.51 MB
5a8a245abd1c: Loading layer [==================================================>] 338.4 kB/338.4 kB
51734435c93c: Loading layer [==================================================>] 10.44 MB/10.44 MB
6599033b2ab2: Loading layer [==================================================>] 4.472 MB/4.472 MB
414373ffccb4: Loading layer [==================================================>] 1.536 kB/1.536 kB
2a9aab74013a: Loading layer [==================================================>] 46.15 MB/46.15 MB
7055b7f82e4c: Loading layer [==================================================>]  34.3 kB/34.3 kB
398ef8a407f7: Loading layer [==================================================>] 3.584 kB/3.584 kB
fc12e028de3b: Loading layer [==================================================>] 321.7 MB/321.7 MB
934de0c0816e: Loading layer [==================================================>] 15.87 kB/15.87 kB
94a471180601: Loading layer [==================================================>] 1.536 kB/1.536 kB
Loaded image: mysql:5.7
[root@localhost docker]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               5.7                 1e4405fe1ea9        2 weeks ago         437 MB

3.2 创建容器

[root@localhost /]#  docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
1fcf644fb24c4731f70ca66edc96847452e898de7612de05b4dd188b3965883c
run                 运行一个docker容器
--name              后面这个是生成的容器的名字mysql
-p 3306:3306        表示这个容器中使用3306(第二个)映射到本机的端口号也为3306(第一个) 
-e MYSQL_ROOT_PASSWORD=123456  初始化root用户的密码
-d                   表示使用守护进程运行,即服务挂在后台
[root@localhost docker]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
1fcf644fb24c        mysql:5.7           "docker-entrypoint..."   25 seconds ago      Up 23 seconds       0.0.0.0:3306->3306/tcp, 33060/tcp   mysql

3.3 允许外部访问

# 进入容器
[root@localhost docker]# docker exec -it mysql /bin/bash
root@1fcf644fb24c:/# mysql -uroot -p123456

mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456";
mysql> flush privileges;

mysql> exit;
Bye
root@1fcf644fb24c:/# exit;
exit

3.4 启动服务

[root@localhost docker]# docker start mysql 

3.5 停止服务

[root@localhost docker]# docker stop mysql 

3.6 服务信息

服务     mysql
版本     5.7
用户名    root
密码     123456

标签:kB,Loading,MB,离线,Centos7,mysql,Docker,root,docker
来源: https://blog.csdn.net/qq_15769939/article/details/112750515

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有