当前位置:网站首页>Docker installation of MySQL and redis

Docker installation of MySQL and redis

2022-06-11 06:15:00 Grumpy procedural ape

centos install docker step
here

start-up docker service

systemctl start docker

Set up docker Boot up

systemctl enable docker

View all mirrors

docker images
	
REPOSITORY           TAG            IMAGE ID       CREATED         SIZE
redis                latest         7faaec683238   7 months ago    113MB
tomcat               9.0            9427bc9144fa   8 months ago    680MB
nacos/nacos-server   latest         bdf60dc2ada3   10 months ago   1.05GB
hello-world          latest         d1165f221234   15 months ago   13.3kB
zookeeper            3.5.7          6bd990489b09   2 years ago     245MB
mysql                5.7.26         e9c354083de7   2 years ago     373MB
redis                3.2            87856cc39862   3 years ago     76MB

Pull mysql5.7 Version image

docker pull mysql:5.7	

Running the mirror

docker run --name mysql 

-v /mydata/mysql/data:/var/lib/mysql\ 

-v /mydata/mysql/conf:/etc/mysql\

 -v /mydata/mysql/log:/var/log/mysql\  
 
-e MYSQL_ROOT_PASSWORD=root\   

-p 3306:3306 -d mysql:5.7

Parameters
-v /mydata/mysql/data:/var/lib/mysql\ Mount the data file to the host : The first one is the destination address of the host : The following is the directory address in the container

-v /mydata/mysql/conf:/etc/mysql\ Mount the configuration file to the host

-v /mydata/mysql/log:/var/log/mysql\ Mount the log file to the host

View the running container

docker ps
[root~]# docker p
CONTAINER ID   IMAGE                COMMAND                  CREATED        STATUS                    PORTS                    NAMES
6f2e3327238f   mysql:5.7.26         "docker-entrypoint.s…"   6 months ago   Exited (0) 6 months ago                            mysql

Go to interactive mysql in

docker exec -it 6f2e3327238f /bin/bash

modify mysql Configuration file for Set character encoding, etc
vim /mydata/mysql/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
skip-character-set-client-handshake
skip-name-resolve

restart mysql docker restart mysql

install redis

Pull the mirror image

docker pull redis

start-up redis
Create folder
mkdir -p /mydata/redis/conf
touch /mydata/redis/conf/redis.conf

docker run -p 6379:6379  --name redi -v /mydata/redis/data:/data\
-v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf\
-d redis redis-server /etc/redis/redis.conf  --privileged=true

Be careful , The latest version of the command is different , Inside the container conf The location of the file changes to /usr/local/etc/redis/redis.conf

mkdir -p /mydata/redis/conf
touch /mydata/redis/conf/redis.con

Enter into redis Console

docker exec -it redis redis-cli

Turn on redis Persistence
vim /mydata/redis/conf/redis.conf
Join in

bind 0.0.0.0  Open remote permissions 
appendonly yes  Turn on aof Persistence 

restart redis
docker restart redis

原网站

版权声明
本文为[Grumpy procedural ape]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110600539799.html