docker-compose 定义和管理多容器 Docker 应用程序(flowable-ui)

0 阅读2分钟

docker-compose 文件是一个 YAML 格式的配置文件,用于定义和管理多个容器的 Docker 应用程序。通过 docker-compose 文件,你可以轻松地配置和启动一个包含多个服务(容器)的复杂应用程序,而无需手动运行多个 docker run 命令。

安装

  1. 通过包管理器安装

    • Ubuntu/Debian: sudo apt-get update sudo apt-get install -y docker-compose

    • CentOS

      sudo yum install -y docker-compose

    • 通过 curl 安装

     sudo curl -L "https://github.com/docker/compose/releases/download/$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep -Po '"tag_name": "\K.*\d')" /usr/local/bin/docker-compose
        sudo chmod +x /usr/local/bin/docker-compose

主要功能

  1. 定义服务

    • 你可以定义多个服务,每个服务对应一个容器。例如,一个 Web 应用程序可能包括一个 Web 服务器、一个数据库服务器和一个缓存服务器。
  2. 配置网络

    • 你可以定义网络,以便容器之间可以相互通信。
  3. 配置卷

    • 你可以定义数据卷,以便在容器之间共享数据或持久化数据。
  4. 环境变量

    • 你可以为每个服务设置环境变量,以便在容器中使用。
  5. 依赖关系

    • 你可以定义服务之间的依赖关系,确保某些服务在其他服务启动后才启动。

示例

以下是一个简单的 docker-compose.yml 文件示例,用于启动一个包含 Web 服务器和数据库的服务:

version: '3.8'

services:
  web:
    image: nginx:latest
    ports:
      - "80:80"
    volumes:
      - ./html:/usr/share/nginx/html
    depends_on:
      - db

  db:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: example
      MYSQL_DATABASE: mydb
      MYSQL_USER: user
      MYSQL_PASSWORD: password
    volumes:
      - db_data:/var/lib/mysql

volumes:
  db_data:

文件结构解释

  1. version

    • 指定 Docker Compose 文件的版本。不同版本的 Docker Compose 文件格式可能有所不同。
  2. services

    • 定义了应用程序中的服务。每个服务都有自己的配置,如镜像、端口映射、环境变量等。
  3. image

    • 指定服务使用的 Docker 镜像。
  4. ports

    • 定义端口映射,将容器的端口映射到宿主机的端口。
  5. volumes

    • 定义数据卷,用于持久化数据或共享数据。
  6. environment

    • 定义环境变量,用于在容器中设置配置。
  7. depends_on

    • 定义服务之间的依赖关系,确保某些服务在其他服务启动后才启动。
  8. volumes

    • 定义数据卷,用于持久化数据。

使用方法

  1. 创建 docker-compose.yml 文件

    • 将上述内容保存到一个名为 docker-compose.yml 的文件中。
  2. 运行 docker-compose up

    • 在包含 docker-compose.yml 文件的目录中运行以下命令: docker-compose up 后台运行 docker-compose up -d
    • 这将启动所有定义的服务,并根据配置文件中的设置进行配置。
  3. 停止服务

    • 要停止服务,可以运行以下命令:

      docker-compose down
      

优点

  • 简化部署:通过一个文件定义所有服务,简化了多容器应用程序的部署过程。
  • 可重复性:配置文件确保每次部署都是一致的,避免了“在我的机器上可以运行”的问题。
  • 易于管理:可以轻松地启动、停止和管理所有服务。

总结

docker-compose 文件是一个强大的工具,用于定义和管理多容器 Docker 应用程序。通过它,你可以轻松地配置和启动复杂的应用程序,而无需手动管理每个容器。希望这个介绍对你有帮助!

实战案例:flowable-ui docker 搭建

准备下面三个文件

docker-compose.yml
version: '3'

services:
 flowable-ui:
   image: flowable/flowable-ui
   container_name: flowable-ui
   restart: always
   ports:
     - 8080:8080
   volumes:
     - ./flowable-default.properties:/app/WEB-INF/classes/flowable-default.properties
     - ./mysql-connector-java-8.0.27.jar:/app/WEB-INF/lib/mysql-connector-java-8.0.27.jar
flowable-default.properties
server.port=8080
server.servlet.context-path=/flowable-ui
spring.jmx.unique-names=true
# This is needed to force use of JDK proxies instead of using CGLIB
spring.aop.proxy-target-class=false
spring.aop.auto=false
spring.application.name=flowable-ui
spring.banner.location=classpath:/org/flowable/spring/boot/flowable-banner.txt

spring.jmx.default-domain=${spring.application.name}
#
# SECURITY
#
spring.security.filter.dispatcher-types=REQUEST,FORWARD,ASYNC

# Expose all actuator endpoints to the web
# They are exposed, but only authenticated users can see /info and /health abd users with access-admin can see the others
management.endpoints.web.exposure.include=*
# Full health details should only be displayed when a user is authorized
management.endpoint.health.show-details=when_authorized
# Only users with role access-admin can access full health details
management.endpoint.health.roles=access-admin
# Spring prefixes the roles with ROLE_. However, Flowable does not have that concept yet, so we need to override that with an empty string
flowable.common.app.role-prefix=

#
# SECURITY OAuth2
# Examples are for Keycloak
#
#spring.security.oauth2.resourceserver.jwt.issuer-uri=<keycloakLocation>/auth/realms/<realmName>
#spring.security.oauth2.client.registration.keycloak.client-id=<clientId>
#spring.security.oauth2.client.registration.keycloak.client-secret=<clientSecret>
#spring.security.oauth2.client.registration.keycloak.client-name=Flowable UI Keycloak
#spring.security.oauth2.client.registration.keycloak.authorization-grant-type=authorization_code
#spring.security.oauth2.client.provider.keycloak.issuer-uri=<keycloakLocation>/auth/realms/<realmName>
#spring.security.oauth2.client.provider.keycloak.user-name-attribute=preferred_username

#flowable.common.app.security.type=oauth2
#flowable.common.app.security.oauth2.authorities-attribute=groups
#flowable.common.app.security.oauth2.groups-attribute=userGroups
#flowable.common.app.security.oauth2.default-authorities=access-task
#flowable.common.app.security.oauth2.default-groups=flowableUser
#flowable.common.app.security.oauth2.full-name-attribute=name
#flowable.common.app.security.oauth2.email-attribute=email

#
# DATABASE
#

#spring.datasource.driver-class-name=org.h2.Driver
# spring.datasource.url=jdbc:h2:~/flowable-db/engine-db;AUTO_SERVER=TRUE;AUTO_SERVER_PORT=9093;DB_CLOSE_DELAY=-1

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://192.168.101.6:3306/flowable_db?characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC

#spring.datasource.driver-class-name=org.postgresql.Driver
#spring.datasource.url=jdbc:postgresql://localhost:5432/flowable

#spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
#spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=flowablea

#spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
#spring.datasource.url=jdbc:oracle:thin:@localhost:1521:FLOWABLE

#spring.datasource.driver-class-name=com.ibm.db2.jcc.DB2Driver
#spring.datasource.url=jdbc:db2://localhost:50000/flowable

spring.datasource.username=root
spring.datasource.password=wjj179140026




spring.datasource.hikari.poolName=${spring.application.name}
# 10 minutes
spring.datasource.hikari.maxLifetime=600000
# 5 minutes
spring.datasource.hikari.idleTimeout=300000
spring.datasource.hikari.minimumIdle=10
spring.datasource.hikari.maximumPoolSize=50
# test query for H2, MySQL, PostgreSQL and Microsoft SQL Server
#spring.datasource.hikari.connection-test-query=select 1
# test query for Oracle
#spring.datasource.hikari.connection-test-query=SELECT 1 FROM DUAL
# test query for DB2
#spring.datasource.hikari.connection-test-query=SELECT current date FROM sysibm.sysdummy1

#
# Default Task Executor (will be used for @Async)
#
spring.task.execution.pool.core-size=2
spring.task.execution.pool.max-size=50
spring.task.execution.pool.queue-capacity=10000
spring.task.execution.thread-name-prefix=flowable-ui-task-Executor-


# Task scheduling

spring.task.scheduling.pool.size=5


flowable.process.definition-cache-limit=512
#flowable.dmn.strict-mode=false
flowable.process.async.executor.default-async-job-acquire-wait-time=PT5S
flowable.process.async.executor.default-timer-job-acquire-wait-time=PT5S

flowable.cmmn.async.executor.default-async-job-acquire-wait-time=PT5S
flowable.cmmn.async.executor.default-timer-job-acquire-wait-time=PT5S

# The maximum file upload limit. Set to -1 to set to 'no limit'. Expressed in bytes
spring.servlet.multipart.max-file-size=10MB
# The maximum request size limit. Set to -1 to set to 'no limit'.
# When multiple files can be uploaded this needs to be more than the 'max-file-size'.
spring.servlet.multipart.max-request-size=10MB

# For development purposes, data folder is created inside the sources ./data folder
flowable.content.storage.root-folder=data/
flowable.content.storage.create-root=true

flowable.common.app.idm-admin.user=admin
flowable.common.app.idm-admin.password=15773272279wt..A

flowable.experimental.debugger.enabled=false

# Rest API in task application

# If false, disables the rest api in the task app
flowable.task.app.rest-enabled=true

# Configures the way user credentials are verified when doing a REST API call:
# 'any-user' : the user needs to exist and the password need to match. Any user is allowed to do the call (this is the pre 6.3.0 behavior)
# 'verify-privilege' : the user needs to exist, the password needs to match and the user needs to have the 'rest-api' privilege
# If nothing set, defaults to 'verify-privilege'
flowable.rest.app.authentication-mode=verify-privilege

# Enable form field validation after form submission on the engine side
flowable.form-field-validation-enabled=false


flowable.admin.app.security.encryption.credentials-i-v-spec=j8kdO2hejA9lKmm6
flowable.admin.app.security.encryption.credentials-secret-spec=9FGl73ngxcOoJvmL


flowable.idm.app.admin.user-id=admin
flowable.idm.app.admin.password=15773272279wt..A
flowable.idm.app.admin.first-name=admin
flowable.idm.app.admin.last-name=Administrator
flowable.idm.app.admin.email=admin@flowable.me
mysql-connector-java-8.0.27.jar
wget https://raw.githubusercontent.com/Selenium39/flowable-ui/refs/heads/master/mysql-connector-java-8.0.27.jar

参考:github.com/Selenium39/…

结果:

image.png

image.png

ACT_ID_USER

admin 15773272279wt..A 更新用户密码

UPDATE ACT_ID_USER SET PASSWORD = 'new_password' WHERE ID_ = 'admin';

image.png

官方文档 flowable.me/blog/2025/0…

Flowable中的四种核心流程控制模式:会签、或签、分支与并行

会签流程的特点

  • 多人必须全部完成任务才能继续流程
  • 可设置驳回机制,任一人拒绝即可终止流程
  • 可配置顺序执行或并行执行

image.png

或签流程的特点

  • 任意一人完成任务即可继续流程
  • 适合平级审批或并行审批场景
  • 提高审批效率,避免流程阻塞

image.png

分支流程的特点

  • 基于条件表达式动态选择流程路径
  • 可实现复杂的业务决策逻辑
  • 支持默认路径设置

image.png

并行流程的特点

  • 多个任务可同时执行,互不干扰
  • 可设置同步点,等待所有分支完成
  • 提高流程执行效率,缩短总处理时间

image.png