Install docker under centos7, provide mysql, redis services
docker installation
1. Installation dependencies
yum install -y yum-utils device-mapper-persistent-data lvm2
2. Add source
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
3. Installation
yum install docker-ce
4. Start docker
systemctl start docker
docker provides mysql service
1. Install mysql mirror
docker pull mysql:5.6.35
2. Build & start the mysql container
docker run --name blankmysql -p 1234:3306 -e MYSQL_ROOT_PASSWORD=my-pass -d mysql:5.6.35
Explanation:
--name specifies the name of the container
-p server mapping port: mysql port maps the server port to the docker mysql container port
-e MYSQL_ROOT_PASSWORD=my-pass specifies the mysql root user password as my-pass
-d mysql:5.6.35 Specify mirror and TAG
3. Test connection The
cloud server opens the corresponding port security group and uses Navicat to test the connection
or
use the command line test to
view the running container
docker ps
docker exec -it 容器id bash
mysql -u root -p
输入上面设置的密码登录数据库
Docker provides redis service
1. Install redis mirror
docker pull redis
2. Build & start redis container
docker run --name blankredis -p 1235:6379 -v $PWD/data:/data -d redis redis-server --appendonly yes --requirepass my-pass
Explanation:
--name set container name
-p server mapping port: redis port
-v $PWD/data:/data mount redis data directory to server data directory
--appendonly yes enable AOF mode for data persistence
--requirepass setting redis password
3. Test the connection
Use RedisDesktopManager to test the connection