window10下使用docker搭建开发环境

使用docker搭建开发环境

包括搭建一个centos7.6的linux服务器,一个mysql服务(数据永久存储),一个redis服务

1、安装centos7.6,做为开发环境:

  1. 拉取镜像:
docker pull centos:centos7.6.1810  
  1. 启动实例:
docker run -itd --restart=always --name centos7.6 --privileged=true -p 1023:22 -p 808:8080 centos:centos7.6.1810 /usr/sbin/init
  1. 进入容器命令行工具:
docker exec -it centos7.1 sh
  1. 安装常用包:
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容器:

  1. 拉取镜像
    docker pull mysql:latest
  2. 启动实例:
    提前创建要用到的目录和配置文件:
    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


  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
  1. 进入命令行工具:
docker exec -it mysql8.0 sh

mysql -h localhost -u root -p
  1. 修改密码加密方式:
ALTER user 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'bc123456';
  1. 使用mysql管理工具连接:
    地址:localhost
    端口:3306

3、安装redis,运行redis容器:

  1. 拉取镜像
    docker pull redis:latest

  2. 运行容器:
    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”

  3. 进入命令行工具:
    docker exec -it redis-server sh

  4. 进入redis客户端:
    redis-cli

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值