Docker-Compose总集

MYSQL

docker-compose.yml

version: "3.8"
services:
  mysql:
    image: mysql:8.1 #镜像名称以及版本
    #限制docker容器的内存
    deploy:
      resources:
          limits:
             memory: 1G
    restart: always #重启docker后该容器也重启
    container_name: mysql8 #容器名称
    environment:
      MYSQL_ROOT_PASSWORD: root #指定用户密码
      TZ: Asia/Shanghai
    ports:
      - 3306:3306 #本地端口号与容器内部端口号
    volumes: #指定挂载目录
      - ./data:/var/lib/mysql
      - ./conf/my.cnf:/etc/mysql/my.cnf

my.cnf

[mysqld]
user=mysql
default-storage-engine=INNODB
character-set-server=utf8
max_connections=1000
bind-address = 0.0.0.0

[client]
default-character-set=utf8mb4

[mysql]
default-character-set=utf8mb4

Redis

docker-compose.yml

version: "3.8"
services:
  redis:
    restart: always
    image: redis
    ports:
      - 6379:6379
    volumes:
      - ./config:/opt/config
      - ./data:/data
    command: redis-server /opt/config/redis.conf
    container_name: redis

redis.conf

# 开启 AOF 持久化
appendonly yes

# 指定 AOF 文件名
appendfilename "appendonly.aof"

# 指定 AOF 文件保存目录
dir /data

# 关闭 RDB 持久化
save ""
# 开启 RDB 持久化
#save 900 1
#save 300 10
#save 60 10000

# 禁用 Redis 的保护模式,允许外部连接
protected-mode no

# 允许其他服务访问
bind 0.0.0.0

# 指定 Redis 监听的端口
port 6379

# 指定日志生成的文件
#logfile /var/log/redis/redis.log

Elasticsearch

docker-compose.yml

version: "3.8"
services:
  elasticsearch:
    image: elasticsearch:8.1.0
    container_name: elasticsearch
    # restart: always
    ports:
      - 9200:9200
      - 9300:9300
    environment:
      - TZ=Asia/Shanghai
      - discovery.type=single-node
      - ES_JAVA_OPTS=-Xms1024m -Xmx1024m
    volumes:
      #  - ./config:/usr/share/elasticsearch/config
      - ./plugins:/usr/share/elasticsearch/plugins
    networks:
      - elastic
  kibana:
    container_name: kibana
    image: kibana:8.1.0
    ports:
      - 5601:5601
    networks:
      - elastic
networks:
  elastic:
    driver: bridge

Jenkins

docker-compose.yml

version: "3.8"
services:
  jenkins:
    image: jenkins/jenkins:2.401.3-lts-jdk17
    container_name: jenkins
    restart: always
    ports:
      - 8081:8080
      - 50000:50000
    volumes:
      - ./data/:/var/jenkins_home/
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/bin/docker:/usr/bin/docker
      - /etc/docker/daemon.json:/etc/docker/daemon.json
      - ./java.security:/opt/java/openjdk/conf/security/java.security
    environment:
      - TZ=Asia/Shanghai

若要拉取SVN代码需要将java.security文件中的该Key改为下方对应的值

jdk.tls.disabledAlgorithms=SSLv3, RC4, DES, MD5withRSA, \
    DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL

在Jenkins中使用外部Docker命令

将外部的docker.sock文件改成root用户并且授权

cd /var/run
chown root:root docker.sock
chmod o+rw docker.sock

Minio

docker-compose.yml

version: "3.8"
services:
  minio:
    image: minio/minio #镜像名称以及版本
    #限制docker容器的内存
    deploy:
      resources:
          limits:
             memory: 1G
    restart: always #重启docker后该容器也重启
    container_name: minio  #容器名称
    environment:
      TZ: Asia/Shanghai
      MINIO_ACCESS_KEY: admin
      MINIO_SECRET_KEY: admin
    volumes:
      - ./data:/data
    ports:
      - 9000:9000
      - 9090:9090  #本地端口号与容器内部端口号
    command: server /data --console-address ":9090" -address ":9000"

RabbitMQ

docker-compose.yml

version: "3.8"
services:
  rabbitmq:
    image: rabbitmq:3.12.8-management #镜像名称以及版本
    #限制docker容器的内存
    deploy:
      resources:
          limits:
             memory: 1G
    restart: always #重启docker后该容器也重启
    container_name: rabbitmq #容器名称
    environment:
      TZ: Asia/Shanghai
    ports:
      - 5672:5672
      - 15672:15672  #本地端口号与容器内部端口号

Typecho

docker-compose.yml

version: "3.8"
services:
  nginx-typecho:
    image: 80x86/typecho  #镜像名称以及版本
    #限制docker容器的内存
    deploy:
      resources:
          limits:
             memory: 1G
    restart: always #重启docker后该容器也重启
    container_name: nginx-typecho #容器名称
    environment:
      TZ: Asia/Shanghai
    ports:
      - 81:80 #本地端口号与容器内部端口号
    volumes: #指定挂载目录
      - ./data:/data

Nginx

docker-compose.yml

version: "3.8"
services:
  nginx:
    image: nginx:1.25  #镜像名称以及版本
    #限制docker容器的内存
    deploy:
      resources:
          limits:
             memory: 2G
    restart: always #重启docker后该容器也重启
    container_name: nginx #容器名称
    environment:
      TZ: Asia/Shanghai
    ports:
      - 80:80 #本地端口号与容器内部端口号
    volumes: #指定挂载目录
      - ./conf/default.conf:/etc/nginx/conf.d/default.conf
      - ./html:/usr/share/nginx/html

default.conf

server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

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

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

SkyWalking

java-agent

https://mirrors.cloud.tencent.com/apache/skywalking/java-agent/9.1.0/

java服务启动vm参数

-javaagent:D:\env\skywalking-agent\skywalking-agent.jar
-Dskywalking.agent.service_name=ruoyi-system
-Dskywalking.collector.backend_service=localhost:11800

docker-compose.yml

version: "3.8"
services:
  elasticsearch:
    image: elasticsearch:6.8.1
    container_name: elasticsearch-6.8.1
    restart: always
    ports:
      - 9200:9200
    environment:
      discovery.type: single-node  #es单机模式
      TZ: Asia/Shanghai  #时区设置
      TAKE_FILE_OWNERSHIP: true  #解决 volumes 挂载权限问题
      ES_JAVA_OPTS: -Xms256m -Xmx256m ##jvm内存分配为256MB
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - ./elasticsearch/data:/usr/share/elasticsearch/data
  oap:
    image: apache/skywalking-oap-server:8.5.0-es6
    container_name: skywalking-oap-8.5.0
    depends_on:
      - elasticsearch
    links:
      - elasticsearch
    restart: always
    ports:
      - 11800:11800
      - 12800:12800
    environment:
      SW_STORAGE: elasticsearch
      SW_STORAGE_ES_CLUSTER_NODES: elasticsearch:9200
      SW_HEALTH_CHECKER: default
      SW_TELEMETRY: prometheus
    healthcheck:
      test: ["CMD", "./bin/swctl", "ch"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
  ui:
    image: apache/skywalking-ui:8.5.0
    container_name: skywalking-ui-8.5.0
    depends_on:
      - oap
    links:
      - oap
    restart: always
    ports:
      - 8888:8080
    environment:
      SW_OAP_ADDRESS: oap:12800

Nacos

docker-compose.yml

version: "3.8"
services:
  mysql:
    image: mysql:8.1 #镜像名称以及版本
    #限制docker容器的内存
    deploy:
      resources:
          limits:
             memory: 1G
    restart: always #重启docker后该容器也重启
    container_name: mysql8 #容器名称
    environment:
      MYSQL_ROOT_PASSWORD: root #指定用户密码
      TZ: Asia/Shanghai
    ports:
      - 3306:3306 #本地端口号与容器内部端口号
    volumes: #指定挂载目录
      - ./data:/var/lib/mysql
      - ./conf/my.cnf:/etc/mysql/my.cnf
    networks:
      - mysql_nacos_network
    healthcheck:
      test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
      interval: 5s
      timeout: 10s
      retries: 10
  nacos:
    image: nacos/nacos-server:v2.3.0
    container_name: nacos-standalone
    env_file:
      - ./nacos-env/nacos-standlone-mysql.env
    volumes:
      - ./standalone-logs/:/home/nacos/logs
    ports:
      - "8848:8848"
      - "9848:9848"
    restart: always
    networks:
      - mysql_nacos_network
    depends_on:
      mysql:
        condition: service_healthy
networks:
  mysql_nacos_network:
    driver: bridge

nacos-standlone-mysql.env

NACOS_CORE_AUTH_ENABLED=true
PREFER_HOST_MODE=hostname
MODE=standalone
SPRING_DATASOURCE_PLATFORM=mysql
MYSQL_SERVICE_HOST=mysql8
MYSQL_SERVICE_DB_NAME=nacos
MYSQL_SERVICE_PORT=3306
MYSQL_SERVICE_USER=root
MYSQL_SERVICE_PASSWORD=root
MYSQL_SERVICE_DB_PARAM=characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
NACOS_AUTH_IDENTITY_KEY=nacos
NACOS_AUTH_IDENTITY_VALUE=nacos
NACOS_AUTH_TOKEN=SecretKey012345678901234567890123456789012345678901234567890123456789

my.cnf使用默认的配置即可

Postgres

docker-compose.yml

services:
  postgres:
    image: postgres:14 #镜像名称以及版本
    #限制docker容器的内存
    deploy:
      resources:
          limits:
             memory: 1G
    # restart: always #重启docker后该容器也重启
    container_name: postgres  #容器名称
    environment:
      POSTGRES_PASSWORD: postgres
    volumes:
      - ./data:/var/lib/postgresql/data
    ports:
      - 5432:5432
最后修改:2024 年 09 月 09 日
如果觉得我的文章对你有用,请随意赞赏