java开发docker-compose常用软件一键高效部署

董嘉祯
2023-12-01

安装及使用见:

Centos7 docker docker-compose安装及镜像部署常用操作_XYLANCC的博客-CSDN博客

docker-compose.yml

version: '3.3'
services:

  nginx:
    image: nginx:1.19.2
    container_name: nginx
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ./nginx/html:/usr/share/nginx/html:ro
      - ./nginx/conf/nginx.conf:/etc/nginx/nginx.conf
      - ./nginx/logs:/var/log/nginx
      - ./nginx/conf.d:/etc/nginx/conf.d
    restart: always
    ports:
      - "80:80"
    environment:
      - NGINX_PORT=80

  mysql:
    image: mysql:5.7.30
    container_name: mysql
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ./mysql/data:/var/lib/mysql
      - ./mysql/conf:/etc/mysql/conf.d
      - ./mysql/logs:/logs
    command: [
          'mysqld',
          '--innodb-buffer-pool-size=80M',
          '--character-set-server=utf8mb4',
          '--collation-server=utf8mb4_unicode_ci',
          '--default-time-zone=+8:00',
          '--lower-case-table-names=1'
        ]
    restart: always
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: root
#      MYSQL_DATABASE: db_manage
#      MYSQL_USER: dev_user
#      MYSQL_PASSWORD: dev_user

  tomcat:
    image: tomcat:9.0.59-jdk8
    container_name: tomcat
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ./tomcat/webapps:/usr/local/tomcat/webapps
      - ./tomcat/logs:/usr/local/tomcat/logs
    environment:
      TZ: Asia/Shanghai
    restart: always
    ports:
      - "8080:8080"

  redis:
    image: redis
    container_name: redis
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ./redis/data:/data
      - ./redis/conf/redis.conf:/usr/local/redis/redis.conf
    command: redis-server /usr/local/redis/redis.conf
    restart: always
    ports:
      - "6379:6379"

#oracle19c 注意给./oradata文件夹777权限,连接服务名:ORCLPDB1,角色:SYSDBA,用户名:sys
  oracle:
    image: registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c
    container_name: oracle19c
    privileged: true
    environment:
      TZ: Asia/Shanghai
      ORACLE_SID: ORCL
      ORACLE_PDB: ORCLPDB1
      ORACLE_PWD: nV1SupBTqqfINz
      ORACLE_EDITION: standard
      ORACLE_CHARACTERSET: AL32UTF8
   volumes:
      - ./oradata:/opt/oracle/oradata
   ports:
      - "1521:1521"
      - "18080:8080"
      - "15313:5500"

#oracle11g
  oracle:
    image: registry.aliyuncs.com/helowin/oracle_11g
    container_name: oracle
    stdin_open: true
    tty: true
    restart: always
    ports:
      - 1521:1521
    volumes:
      - ./dpdump:/home/oracle/app/oracle/admin/orcl/dpdump/
    privileged: true

  jenkins:
    image: 'jenkinsci/blueocean'    # 镜像
    container_name: jenkins         # 容器名称
    privileged: true				# 解决权限问题
    restart: always                 # 同 --restart 参数
    ports:                          # 端口映射,同 -p 参数,本地端口:容器端口
      - '8080:8080'
      - '50000:50000'
    volumes:                        # 数据卷,本地文件夹:容器文件夹
      - ./jenkins/jenkins_home:/var/jenkins_home

#部署rocketmq------start------
  rmqnamesrv:
    image: foxiswho/rocketmq:server
    container_name: rmqnamesrv
    ports:
      - 9876:9876
    volumes:
      - ./rocketmq/logs:/opt/logs
      - ./rocketmq/store:/opt/store

  rmqbroker:
    image: foxiswho/rocketmq:broker
    container_name: rmqbroker
    ports:
      - 10909:10909
      - 10911:10911
    volumes:
      - ./rocketmq/logs:/opt/logs
      - ./rocketmq/store:/opt/store
      - ./rocketmq/brokerconf/broker.conf:/etc/rocketmq/broker.conf
    environment:
        NAMESRV_ADDR: "rmqnamesrv:9876"
        JAVA_OPTS: " -Duser.home=/opt"
        JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"
    command: mqbroker -c /etc/rocketmq/broker.conf
    depends_on:
      - rmqnamesrv

  rmqconsole:
    image: styletang/rocketmq-console-ng
    container_name: rmqconsole
    ports:
      - 18080:18080
    environment:
        JAVA_OPTS: "-Drocketmq.namesrv.addr=rmqnamesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"
    depends_on:
      - rmqnamesrv
#部署rocketmq------end------

  memecached:
    image: memcached:1.6.7
    container_name: memcached
    volumes:
      - /etc/localtime:/etc/localtime:ro
    restart: always
    ports:
      - "21605:11211"

  mongo:
    image: mongo:4.4.1
    container_name: mongo
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ./mongo/config:/etc/mongo  # 挂载配置目录
      - ./mongo/db:/data/db # 挂载数据目录
      - ./mongo/log:/var/log/mongodb  # 挂载日志目录
    restart: always
    ports:
      - "27017:27017"
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: Admin2020

  clickhouse:
    image: yandex/clickhouse-server:20.6.6.7
    container_name: ${COMMON_DEPLOY_ENV}-clickhouse
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ./clickhouse-server:/var/lib/clickhouse yandex/clickhouse-server
    restart: always
    ports:
      - "21607:8123"

#部署ELK------start------
  elasticsearch:
    image: elasticsearch:7.2.0
    container_name: elasticsearch
    restart: always
    environment:
      #设置集群名称为elasticsearch
      - "cluster.name=elasticsearch"
      #以单一节点模式启动
      - "discovery.type=single-node"
      #设置使用jvm内存大小
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    volumes:
        #注意设置目录权限777,否则无法启动
      - ./docker_elk/elasticsearch/plugins:/usr/share/elasticsearch/plugins
      - ./docker_elk/elasticsearch/data:/usr/share/elasticsearch/data
      - ./docker_elk/elasticsearch/logs:/usr/share/elasticsearch/logs
      - ./docker_elk/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
    ports:
      - 9200:9200

  logstash:
    image: logstash:7.2.0
    container_name: logstash
    ports:
       - 4560:4560
    restart: always
    environment:
      - TZ=Asia/Shanghai
    volumes:
      #挂载logstash的配置文件,文件需要手动拷贝,见文章后
      - ./docker_elk/logstash/logstash.conf:/usr/share/logstash/pipeline/logstash.conf
    depends_on:
      - elasticsearch
    links:
      #可以用es这个域名访问elasticsearch服务
      - elasticsearch:es

  #需要项目日志接入ELK后才能创建索引模式
  kibana:
    image: kibana:7.2.0
    container_name: kibana
    volumes:
      #挂载logstash的配置文件,文件需要手动拷贝,见文章后
      - ./docker_elk/kibana/kibana.yml:/usr/share/kibana/config/kibana.yml
    ports:
        - 5601:5601
    restart: always
    links:
      #可以用es这个域名访问elasticsearch服务
      - elasticsearch:es
    depends_on:
      - elasticsearch
    environment:
      #设置访问elasticsearch的地址
      - ELASTICSEARCH_URL=http://elasticsearch:9200
#部署ELK------end------


  minio:
    image: minio/minio:latest
    container_name: minio
    environment:
      MINIO_ROOT_USER: admin
      MINIO_ROOT_PASSWORD: 12345678
    volumes:
      - ./minio:/data
    ports:
      #暴露API接口
      - 9000:9000
      #暴露Web接口控制台端口
      - 9001:9001  
    command: minio server /data --console-address ":9001"

  gitlab:
    image: 'twang2218/gitlab-ce-zh'
    restart: always
    hostname: '192.168.1.100' # 此处填写所在服务器ip
    environment:
      TZ: 'Asia/Shanghai'
      # 此处 ip 须与上面 hostname 一致,端口号自定义
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://192.168.1.100'
        gitlab_rails['gitlab_shell_ssh_port'] = 2222
        unicorn['port'] = 8888
        nginx['listen_port'] = 80
    ports:
      - '80:80'
      - '8443:443'
      - '2222:22'
    volumes:
      - ./gitlab/config:/etc/gitlab
      - ./gitlab/data:/var/opt/gitlab
      - ./gitlab/logs:/var/log/gitlab

  nexus:
    restart: always
    image: sonatype/nexus3
    container_name: nexus
    ports:
      - 8081:8081
    volumes:
      - ./nexus-data:/nexus-data

####registry:docker私服
  registry:
    image: registry
    restart: always
    container_name: registry
    ports:
      - 5000:5000
    volumes:
      - ./docker/registry/data:/var/lib/registry

#部署FastDFS文件服务器------start------
  tracker:
    image: season/fastdfs:1.2
    container_name: tracker
    restart: always
    volumes:
      - "./fastdfs/tracker_data:/fastdfs/tracker/data"
    ports: 
      - "22122:22122"
    command: "tracker" 
 
  storage:
    image: season/fastdfs:1.2
    container_name: storage
    links: 
      - tracker
    restart: always
    volumes:
      - "./fastdfs/storage.conf:/fdfs_conf/storage.conf"
      - "./fastdfs/storage_base_path:/fastdfs/storage/data"
      - "./fastdfs/store_path0:/fastdfs/store_path"  
    ports: 
      - "23000:23000"
    environment:
      TRACKER_SERVER: "tracker:22122"
    command: "storage"
 
  nginx:
    image: season/fastdfs:1.2
    container_name: fdfs-nginx
    restart: always
    volumes:
      - "./fastdfs/nginx.conf:/etc/nginx/conf/nginx.conf"
      - "./fastdfs/store_path0:/fastdfs/store_path"
    links: 
      - tracker
    ports: 
      - "8088:8088"
    environment:
      TRACKER_SERVER: "tracker:22122"
    command: "nginx"
#部署FastDFS文件服务器------end------

配置网络示例

version: '3.3'
services:

  nginx:
    image: nginx:1.19.2
    container_name: nginx
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ./nginx/html:/usr/share/nginx/html:ro
      - ./nginx/conf/nginx.conf:/etc/nginx/nginx.conf
      - ./nginx/logs:/var/log/nginx
      - ./nginx/conf.d:/etc/nginx/conf.d
    restart: always
    ports:
      - "80:80"
    environment:
      - NGINX_PORT=80
    networks:
      sly_net_pro:
        ipv4_address: 172.172.0.1

networks:
  sly_net_pro:
    ipam:
      driver: default
      config:
        - subnet: "172.172.0.0/24"

 springboot + logback异步输出日志到logstash_XYLANCC的博客-CSDN博客

 elasticsearch.yml

network.host: 0.0.0.0  #使用的网络
http.cors.enabled: true #跨域配置
http.cors.allow-origin: "*"
#xpack.security.enabled: true  #开启密码配置

logstash.conf

input {
  tcp {
    host => "0.0.0.0"
    # Logstash 作为服务
    mode => "server"
    # 开放9001端口进行采集日志
    port => 4560
    # 编解码器
    codec => json_lines
  }
}

output {
  elasticsearch {
    hosts => "es:9200"
    # 在ES里产生的index的名称
    index => "app-search-log-collection-%{+YYYY.MM.dd}"
    #user => "elastic"
    #password => "changeme"
  }
}
kibana.yml
#
# ** THIS IS AN AUTO-GENERATED FILE **
#

# Default Kibana configuration for docker target
server.name: kibana
server.host: "0"
elasticsearch.hosts: [ "http://elasticsearch:9200" ]
xpack.monitoring.ui.container.elasticsearch.enabled: true
i18n.locale: "zh-CN"

更多:

GitHub - bboysoulcn/awesome-dockercompose: 一些大家可能会经常使用的docker-compose文件

 类似资料: