常用docker-compose配置!吐血總結(jié)??!

fastDFS

version: '3.1'
services:
 fastdfs:
   build: environment
   restart: always
   container_name: fastdfs
   volumes:
     - ./storage:/fastdfs/storage
   network_mode: host

Spring Cloud Config

version: '3.1'
services:
 itoken-config:
   restart: always
   image: IP地址:端口/itoken-config
   container_name: itoken-config
   ports:
     - 8888:8888
  • Dockerfile文件內(nèi)容
FROM openjdk:8-jre

RUN mkdir /app

COPY itoken-config-1.0.0-SNAPSHOT.jar /app/

CMD java -jar /app/itoken-config-1.0.0-SNAPSHOT.jar --spring.profiles.active=prod

EXPOSE 8888

MySQL

需要在docker-compose.yml同級(jí)目錄分別建立3個(gè)文件夾

  1. conf 配置
  2. data 數(shù)據(jù)
  3. logs 日志
version: '3.1'
services:
 mysql:
   restart: always
   image: mysql:5.7.22
   container_name: itoken_database
   ports:
     - 3306:3306
   environment:
     TZ: Asia/Shanghai
     MYSQL_ROOT_PASSWORD: 123456
   command:
     --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:
     - mysql-data:/var/lib/mysql

volumes:
 mysql-data:

Nginx

需要在docker-compose.yml同級(jí)目錄分別建立2個(gè)文件夾

  1. conf 配置
  2. wwwroot 頁面
version: '3.1'
services:
 nginx:
   restart: always
   image: ip:port/nginx
   container_name: nginx
   ports:
     - 81:80
     # 端口映射根據(jù)需求設(shè)置
     - 9000:9000
   volumes:
     - ./conf/nginx.conf:/etc/nginx/nginx.conf
     - ./wwwroot:/usr/share/nginx/wwwroot

以下是Nginx不帶注釋的配置 nginx.conf

worker_processes  1;

events {
   worker_connections  1024;
}

http {
   include       mime.types;
   default_type  application/octet-stream;

   sendfile        on;

   keepalive_timeout  65;
  
   server {
       listen       80;
       server_name 192.168.231.129;
       location / {
          # Nginx解決瀏覽器跨域問題
          add_header Access-Control-Allow-Origin *;
          add_header Access-Control-Allow-Headers X-Requested-With;
          add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,PATCH,OPTIONS;
          root   /usr/share/nginx/wwwroot/cdn;
          index  index.html index.htm;
       }

   }
}

以下是Nginx帶注釋的配置 nginx.conf

# CPU內(nèi)核數(shù)量
worker_processes  1;
# 每個(gè)內(nèi)核處理多少個(gè)連接
events {
   worker_connections  1024;
}

http {
   include       mime.types;
   default_type  application/octet-stream;

   sendfile        on;
   
   keepalive_timeout  65;
   # 配置虛擬主機(jī) 192.168.231.129
   server {
   # 監(jiān)聽的ip和端口,配置 >192.168.231.129:80
      listen       80;
   # 虛擬主機(jī)名稱這里配置ip地址
   #   server_name  192.168.231.129;
      server_name  daxian.com;
   # 所有的請(qǐng)求都以 / 開始,所有的請(qǐng)求都可以匹配此 location
       location / {
      # 使用 root 指令指定虛擬主機(jī)目錄即網(wǎng)頁存放目錄
      # 比如訪問 http://ip/index.html 將找到 /usr/local/docker/nginx/wwwroot/html80/index.html
      # 比如訪問 http://ip/item/index.html 將找到 /usr/local/docker/nginx/wwwroot/html80/item/index.html

           root   /usr/share/nginx/wwwroot/html81;
      # 指定歡迎頁面,按從左到右順序查找
           index  index.html index.htm;
       }

   }
   # 配置虛擬主機(jī) 192.168.231.129 每開一個(gè)虛擬主機(jī)就是開一個(gè)server
   server {
       listen       9000;
       server_name  192.168.231.129;

       location / {
           root   /usr/share/nginx/wwwroot/html9000;
           index  index.html index.htm;
       }
   }
}

以下是Nginx帶負(fù)載均衡的配置 nginx.conf

# nginx負(fù)載均衡配置
user  nginx;
worker_processes  1;

events {
   worker_connections  1024;
}

http {
   include       mime.types;
   default_type  application/octet-stream;

   sendfile        on;

   keepalive_timeout  65;
  
   upstream myapp1 {
      server 192.168.231.129:9090 weight=10;
      server 192.168.231.129:9091 weight=10;
   }

   server {
      listen 80;
      server_name 192.168.231.129;
      location / {
          proxy_pass http://myapp1;
          index index.jsp index.html index.htm;
      }
   }
}

Redis

version: '3.1'
services:
 master:
   image: redis
   restart: always
   container_name: redis-master
   ports:
     - 6379:6379

 slave1:
   image: redis
   restart: always
   container_name: redis-slave-1
   ports:
     - 6380:6379
   command: redis-server --slaveof redis-master 6379

 slave2:
   image: redis
   restart: always
   container_name: redis-slave-2
   ports:
     - 6381:6379
   command: redis-server --slaveof redis-master 6379

Redis Sentinel

需要docker-compose.yml同級(jí)目錄建立三個(gè)配置文件,文件名分別為sentinel1.conf、sentinel2.confsentinel3.conf

sentinel.conf內(nèi)容為(根據(jù)這份文件復(fù)制3份conf)

port 26379
dir /tmp
# 自定義集群名,其中 127.0.0.1 為 redis-master 的 ip,6379 為 redis-master 的端口,2 為最小投票數(shù)(因?yàn)橛?3 臺(tái) Sentinel 所以可以設(shè)置成 2)
sentinel monitor mymaster 192.168.231.129 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes

docker-compose.yml內(nèi)容為

version: '3.1'
services:
 sentinel1:
   image: redis
   container_name: redis-sentinel-1
   ports:
     - 26379:26379
   command: redis-sentinel /usr/local/etc/redis/sentinel.conf
   volumes:
     - ./sentinel1.conf:/usr/local/etc/redis/sentinel.conf

 sentinel2:
   image: redis
   container_name: redis-sentinel-2
   ports:
     - 26380:26379
   command: redis-sentinel /usr/local/etc/redis/sentinel.conf
   volumes:
     - ./sentinel2.conf:/usr/local/etc/redis/sentinel.conf

 sentinel3:
   image: redis
   container_name: redis-sentinel-3
   ports:
     - 26381:26379
   command: redis-sentinel /usr/local/etc/redis/sentinel.conf
   volumes:
     - ./sentinel3.conf:/usr/local/etc/redis/sentinel.conf

RabbitMQ
需要建立spring-boot-amqp-provider消息隊(duì)列提供者,spring-boot-amqp-consumer消息隊(duì)列消費(fèi)者兩個(gè)項(xiàng)目,并在application.yml設(shè)置連接上RabbitMQ

version: '3.1'
services:
 rabbitmq:
   restart: always
   image: rabbitmq:management
   container_name: rabbitmq
   ports:
     - 5672:5672
     - 15672:15672
   environment:
     TZ: Asia/Shanghai
     RABBITMQ_DEFAULT_USER: rabbit
     RABBITMQ_DEFAULT_PASS: 123456
   volumes:
     - ./data:/var/lib/rabbitmq

Nexus ( Maven私有倉庫 )
需要docker-compose.yml同級(jí)目錄建立一個(gè)data文件夾用于存放數(shù)據(jù)

version: '3.1'
services:
 nexus:
   restart: always
   image: sonatype/nexus3
   container_name: nexus
   ports:
     - 8081:8081
   volumes:
     - /usr/local/docker/nexus/data:/nexus-data

Registry( Docker私有鏡像倉庫 )
需要docker-compose.yml同級(jí)目錄建立兩個(gè)文件夾,分別為certsdata

version: '3.1'
services:
 # registry服務(wù)
 registry:
   image: registry
   restart: always
   container_name: registry
   ports:
     - 5000:5000
   volumes:
     - /usr/local/docker/registry/data:/var/lib/registry
 # 前端頁面
 frontend:
   image: konradkleine/docker-registry-frontend:v2
   restart: always
   ports:
     - 8080:80
   volumes:
     - ./certs/frontend.crt:/etc/apache2/server.crt:ro
     - ./certs/frontend.key:/etc/apache2/server.key:ro
   environment:
     - ENV_DOCKER_REGISTRY_HOST=192.168.231.129
     - ENV_DOCKER_REGISTRY_PORT=5000

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容