docker-compose 安装redis+安装mysql

1.新建一目录/docker
2.新建一文件 docker-compose.yaml

3.写入内容

version: '2'
services:

  #redis
  redis:
    hostname: redis
    image: redis:5.0.4
    container_name: redis
    restart: unless-stopped
    command: redis-server /etc/redis.conf # 启动redis命令
    environment:
      - TZ=Asia/Shanghai
    volumes:
      - /etc/localtime:/etc/localtime:ro # 设置容器时区与宿主机保持一致
      - /docker/redis/data:/data
      - /docker/redis/redis.conf:/etc/redis.conf
    ports:
      - 6379:6379

  #mysql:5.7.23
  mysql:
    hostname: mysql
    image: mysql:5.7.23
    container_name: mysql
    restart: unless-stopped
    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci # 设置utf8字符集
    environment:
      - TZ=Asia/Shanghai
      - MYSQL_ROOT_PASSWORD=123456
    volumes:
      - /etc/localtime:/etc/localtime:ro # 设置容器时区与宿主机保持一致
      - /docker/lnmp/mysql/data:/var/lib/mysql
      - /docker/lnmp/mysql/conf.d:/etc/mysql/conf.d
    ports:
      - 3001:3306

4.拉取镜像

docker-compose pull

5.启动

docker-compose up -d

你可能感兴趣的:(docker)