使用docker搭建开发环境
包括搭建一个centos7.6的linux服务器,一个mysql服务(数据永久存储),一个redis服务
1、安装centos7.6,做为开发环境:
- 拉取镜像:
docker pull centos:centos7.6.1810
- 启动实例:
docker run -itd --restart=always --name centos7.6 --privileged=true -p 1023:22 -p 808:8080 centos:centos7.6.1810 /usr/sbin/init
- 进入容器命令行工具:
docker exec -it centos7.1 sh
- 安装常用包:
yum install -y net-tools
yum install -y passwd
yum install -y openssh-server openssh-clients
systemctl start sshd
yum -y install initscripts
下面就可以通过地址:localhost,端口:1023连接这台Linux服务器
2、安装mysql,运行mysql容器:
- 拉取镜像
docker pull mysql:latest - 启动实例:
提前创建要用到的目录和配置文件:
E:/docker/mysql/data
E:/docker/mysql/config
E:/docker/mysql/mysql-files
my.cnf:
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[mysql]
#设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#服务端使用的字符集默认为8比特编码的latin1字符集
character_set_server = utf8
#创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
#设置不区分大小写
# 必须在安装好MySQL后 修改mySQL配置文件设置为不敏感,一旦启动后,再设置是无效的,而且启动报错;
# 如果已经晚了,那必须把MySQL数据库文件全部 删除,修改配置文件再启动。
lower_case_table_names=1
- 运行容器:
docker run -it -v E:/docker/mysql/data:/var/lib/mysql -v E:/docker/mysql/config/my.cnf:/etc/mysql/my.cnf -v E:/docker/mysql/mysql-files:/var/lib/mysql-files/ --restart=always --name mysql8.0 --privileged -e MYSQL_ROOT_PASSWORD=bc123456 -p 3306:3306 -d mysql
- 进入命令行工具:
docker exec -it mysql8.0 sh
mysql -h localhost -u root -p
- 修改密码加密方式:
ALTER user 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'bc123456';
- 使用mysql管理工具连接:
地址:localhost
端口:3306
3、安装redis,运行redis容器:
-
拉取镜像
docker pull redis:latest -
运行容器:
docker run -d --name redis-server -p 6379:6379 -v E:/docker/redis/redis.conf:/etc/redis/redis.conf -v E:/docker/redis/data/:/data redis:latest /etc/redis/redis.conf --appendonly yes --requirepass “123456” -
进入命令行工具:
docker exec -it redis-server sh -
进入redis客户端:
redis-cli


3828

被折叠的 条评论
为什么被折叠?



