Skip to content

常用docker-compose环境

数据库

mysql

  • mysql8.0
version: "3"
services:
  mysql:
    # restart: always
    restart: no
    privileged: true
    image: mysql:8.0.28
    container_name: mysql8.0
    volumes:
      - ./db:/var/lib/mysql
      - ./conf:/etc/mysql/conf.d
      - ./logs:/logs
    command:
      --default-authentication-plugin=mysql_native_password
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
      --explicit_defaults_for_timestamp=true
    environment:
      TZ: Asia/Shanghai
      MYSQL_ROOT_PASSWORD: "123456"
      MYSQL_USER: "test"
      MYSQL_PASSWORD: "123456"
      MYSQL_INITDB_SKIP_TZINFO: "Asia/Shanghai"
    ports:
      - 33306:3306

redis

version: "3"
services:
  redis:
    image: redis:latest
    container_name: redis
    # restart: always
    ports:
      - "6379:6379"
    volumes:
      # - ./data/redis/conf/:/etc/redis/
      - ./data/redis/data:/data
    command: redis-server --requirepass exchangepwd --save "" --appendonly no

mongo

version: '3.1'
services:
  mongo:
    image: mongo:5.0
    restart: always
    container_name: mongov5
    ports:
      - 27017:27017
    volumes:
      - ./data:/etc/mongo
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example
  mongo-express:
    image: mongo-express:0.54.0
    restart: always
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: example

nginx

基本使用

docker-compose.yml

version: "3.3"
services:
  nginx:
    restart: always
    container_name: nginx
    image: nginx:alpine
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./conf/nginx.conf:/etc/nginx/nginx.conf
      # 放静态网页
      - ./htmls:/usr/share/nginx/htmls
      - ./log:/var/log/nginx
      # conf.d文件下必须要有 default.conf
      - ./conf/conf.d:/etc/nginx/conf.d

常用

  1. 时区问题 一般用东 8 区
  2. 网络问题 一般用 host 网络,如果业务有网络重定向的需求,跳转到其他业务
version: "3.3"
services:
  nginx:
    restart: always
    container_name: nginx
    image: nginx:alpine
    environment:
      - TZ=Asia/Shanghai
    volumes:
      - ./conf/nginx.conf:/etc/nginx/nginx.conf
      - ./htmls:/usr/share/nginx/htmls
      - ./log:/var/log/nginx
      - ./conf/conf.d:/etc/nginx/conf.d
    network_mode: host

Comments