A docker deployment mysql and redis
1. docker install mysql
docker run -p 3306:3306 --name mysql --env MYSQL_ROOT_PASSWORD=123zxc -d mysql:5.7
# 停止容器服务命令
docker stop mysql
2. docker install redis
docker run -d --name myredis -p 6379:6379 redis --requirepass "mypassword"
# 停止redis 容器服务命令
docker stop myredis
Two docker-compose rapid deployment mysql and redis
1. Create a docker-compose.yml file, and fill in the following configurations.
version: '3'
services:
mysql-dev:
image:mysql: 5.7
container_name: mysql-dev
hostname: localhost
network_mode: bridge
ports:
- "3306:3306"
volumes:
- ./mysql:/var/lib/mysql
- ./my.cnf:/etc/mysql/conf.d/my.cnf
environment:
- MYSQL_ROOT_PASSWORD=123zxc
redis-dev:
image: redis:3
container_name: redis-dev
hostname: localhost
network_mode: bridge
command: redis-server /usr/local/etc/redis.conf --requirepass 123zxc
volumes:
- ./redis/redis.conf:/usr/local/etc/redis/redis.conf
ports:
- "6379:6379"
2. Go to the folder where the file docker-compose.yml, execute the command.
docker-compose up
# 注意文件名一定是 docker-compose.yml才能运行成功,若不是这个文件名,则需要指定文件名
docker-compose -f filename up
# filename 对应文件名
# 关闭docker-compose 服务
docker-compose down
# 或者
docker-compose -f filename down
III summarizes
docker start every time | can only operate a closed container, and the use of docker-compose mode you can start one time | closing multiple containers, very convenient!