**步骤: 1.Uninstall old versions(卸载旧版本):
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
2.Set up the repository(安装相关依赖):
sudo yum install -y yum-utils
3.设置镜像地址(用于加速下载docker用,并非docker image镜像)
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
异常:下载docker的镜像报错fastmirror 解决: vi /etc/yum/pluginconf.d/fastestmirror.conf(修改 enable=1 为 enable=0) vi /etc/yum.conf(修改 plugins=1 为 plugins=0) yum clean all rm -rf /var/cache/yum yum makecache
4.安装docker
sudo yum install -y docker-ce docker-ce-cli containerd.io
5、启动docker 设置开机自启:
sudo systemctl enable docker
启动:
sudo systemctl start docker
6、查看docker版本
docker -v
拉去mysql镜像
docker pull mysql:5.7
配置阿里云镜像
sudo mkdir -p/etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors":["https://82m9ar63.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
启动实例并启动
docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7
参数说明: -p 3306:3306 :将容器的3306端口映射到主机的3306端口 -v /mydata/mysql/log:/var/log/mysql :将配置文件挂载到主机 -v /mydata/mysql/data:/var/lib/mysql :将日志文件夹挂载到主机 -v /mydata/mysql/conf:/etc/mysql :将配置文件夹挂载到主机 -e MYSQL_ROOT_PASSWORD=root :初始化root用户的密码为root
配置utf-8
vi /mydata/conf/my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect=‘SET collation_connection = utf8_unicode_ci’
init_connect=‘SET NAMES utf8’
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
重启容器
docker restart mysql
redis
步骤:
1.拉取镜像:docker pull redis
2.坑:使用-v命令挂载时,主机会把redis.conf当做目录创建,所以先将改文件创建好
mkdir -p /mydata/redis/conf
touch /mydata/redis/conf/redis.conf
开启redis持久化:
vi /mydata/redis/conf/redis.conf
appendonly yes
3.启动容器
docker run -p 6379:6379 --name redis \
-v /mydata/redis/data:/data \
-v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
-d redis redis-server /etc/redis/redis.conf
参数说明:
redis-server /etc/redis/redis.conf:该容器redis-server使用/etc/redis/redis.conf配置文件启动
4、自启动:sudo docker update redis --restart=always
docker restart redis
5、终止容器:docker stop redis
删除容器:docker rm redis
6、连接redis:
1)进入容器内部连接:
docker exec -it redis /bin/bash
redis-cli -p 6379
2)使用客户端连接:
docker exec -it redis redis-cli
3)外部windows可视化客户端连接6379端口
标签:mydata,redis,etc,conf,mysql,docker From: https://www.cnblogs.com/huoziqi/p/17548616.html