【Docker-3】Docker-Compose安装常用软件Nginx、Mysql、Redis、Java

创建应用目录结构

nginx

  • conf.d - 放置自定义的配置文件
  • log - 日志存储位置
  • nginx.conf - nginx总配置文件
  • docker-compose.yml

mysql

  • conf - 放置自定义的配置文件
  • logs - 日志存储位置
  • data - 数据库存储位置
  • docker-compose.yml

Redis

  • conf - 放置自定义的配置文件
  • logs - 日志存储位置
  • data - 数据库存储位置
  • docker-compose.yml

Java

  • jar - 放置jar包
    • app.jar
  • logs - 日志存储位置
  • docker-compose.yml

编辑docker-compose

通过vi docker-compose.yml编辑

version: '3.0'
services:
  nginx:
    container_name: nginx
    restart: always
    image: nginx:latest
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./conf.d:/etc/nginx/conf.d
      - ./nginx.conf:/etc/nginx/nginx.conf
      - ./log:/var/log/nginx
    environment:
      - TZ=Asia/Shanghai
    # 拥有外部root权限
    privileged: true
    
  mysql:
    image: mysql:5.7
    container_name: mysql
    restart: always
    ports:
      - 3306:3306
    environment:
      TZ: Asia/Shanghai
      MYSQL_ROOT_HOST: "%"
      MYSQL_ROOT_PASSWORD: 123456
    command:
      --default-time-zone=+8:00
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
      --explicit_defaults_for_timestamp=true
      --lower_case_table_names=1
      --max_allowed_packet=128M
      --sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO"
    volumes:
      - ./conf/my.cnf:/etc/my.cnf
      - ./data:/var/lib/mysql
      - ./logs:/var/log/mysql
    privileged: true
    
  redis:
    image: redis
    container_name: redis
    volumes:
      - ./data:/data
      - ./conf/redis.conf:/usr/local/etc/redis/redis.conf
      - ./logs:/logs
    restart: always
    ports:
      - 6379:6379
    command: redis-server --requirepass 123456
    
  java:
    container_name: java
    restart: always
    image: java:8
    ports:
      - 8080:8080
    volumes:
      - ./jar/app.jar:/root/app.jar:z
      - ./logs/:/root/logs
    environment:
      - TZ=Asia/Shanghai
    entrypoint: java -jar -Dfile.encoding=utf-8 /root/app.jar
    privileged: true

在docker-compose.yml同级目录执行docker-compose up -d进行后台启动应用,可通过docker-compose logs -f查看日志

 

--------------------小马哥原创----------------------

posted @ 2023-02-20 10:04  甜8筒  阅读(468)  评论(0编辑  收藏  举报