常用的Docker-Compose

8/25/2021 Docker

常用的Docker-Compose

本文章代码地址: https://github.com/remember-5/myshell

# 安装Mysql

version: '3'
services:
  mysql:
    restart: always
    image: mysql:8.0.20
    container_name: MYSQL8
    ports:
      - 3306:3306
    environment:
#      - MYSQL_USER: user # 创建新用户
      - "MYSQL_ROOT_PASSWORD=123456"
#      - "MYSQL_DATABASE=mydb" # 创建新的库
      - "TZ=Asia/Shanghai"
    volumes:
      - /data/mysql/data:/var/lib/mysql
      - /data/mysql/conf:/etc/mysql/conf.d
      - /data/mysql/logs:/logs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

简写

docker pull mysql
docker run -p 3306:3306 --name MYSQL8.0 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:latest
1
2

# 安装Redis

version: '3'
services:
  redis:
    image: redis:6.2.5
    restart: always
    container_name: redis
    ports:
      - 6379:6379
    command:
      ["redis-server", "--requirepass", "12345678", "--appendonly", "yes"]
    volumes:
      - /data/redis/data:/data
#      - /data/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf # 配置文件,暂时不需要
      - /data/redis/logs:/logs
1
2
3
4
5
6
7
8
9
10
11
12
13
14

简写

docker pull redis
# 最简单方式
docker run -itd --name redis -p 6379:6379 redis
# 持久化
docker run -d --name redis -p 6379:6379 redis --requirepass "password" --appendonly yes
# 给已创建的 redis 容器创建密码或修改密码的方法
# 进入redis的容器:docker exec -it 容器ID bash
# 运行命令:redis-cli
# 查看现有的redis密码:config get requirepass
# 设置 redis 密码:config set requirepass ****(****为你要设置的密码)
1
2
3
4
5
6
7
8
9
10

# 安装Minio

version: '3.0'
services:
  minio:
    image: minio/minio:RELEASE.2021-06-07T21-40-51Z
    container_name: minio
    ports:
      - "9000:9000"
    restart: always
    command: server /data
    environment:
      MINIO_ACCESS_KEY: admin
      MINIO_SECRET_KEY: admin123 # 大于等于8位
#    logging:
#      options:
#        max-size: "50M" # 最大文件上传限制
#        max-file: "10"
#      driver: json-file
    volumes:
      - /data/minio/data:/data # 映射文件路径
      - /data/minio/config:/root/.minio # 映射配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

# 安装RabbitMQ

version: '3'
services:
  rabbitmq:
    image: rabbitmq:3.9.4-management
    container_name: rabbitmq
    restart: always
#    hostname: rabbitmq
    ports:
      - 15672:15672
      - 5672:5672
    volumes:
      - /data/rabbitmq:/var/lib/rabbitmq
    environment:
      - RABBITMQ_DEFAULT_USER=root
      - RABBITMQ_DEFAULT_PASS=root
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

简写

docker pull rabbitmq:management 
docker run --name rabbitmq -d -p 15672:15672 -p 5672:5672 rabbitmq:management
# 启动容器后,可以浏览器中访问http://localhost:15672来查看控制台信息。 RabbitMQ默认的用户名:guest,密码:guest
1
2
3
Last Updated: 8/25/2021, 9:46:16 PM
我再没见过 像你一般的星空
Seto