Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker Compose 部署 #1

Open
orange-juzipi opened this issue Jun 17, 2024 · 0 comments
Open

Docker Compose 部署 #1

orange-juzipi opened this issue Jun 17, 2024 · 0 comments
Assignees

Comments

@orange-juzipi
Copy link
Owner

commit 29ddb66

该提交完成了 Docker Compose 部署
compose-base.yaml :为基础环境配置
compose.yaml :为 server 服务配置

列下比较重要的知识点:

  1. 所有基础环境和服务均要在同一网络中,配置 networks
  2. 基础环境启动时,Docker 只会检测是否启动,不会检测是否就绪,比如 Mysql,虽然已经使用了depends_on配置等待依赖的环境启动,但无法检测到是否已经就绪,所以需要在Mysql环境中添加healthcheck健康检查,该命令能执行到,证明 Mysql 已经就绪,最后才启动 server。Redis可以不需要healthcheck
    depends_on: # 依赖的服务
      mysql:
        condition: service_healthy # service_healthy 服务已经健康
      redis:
        condition: service_started # service_started 服务已经启动
  1. server 服务的 buildcontext指的是构建路径,.mod 在根路径就填 .就行,但该服务的 Dockerfile 在不同的路径,则需手动填写到对应服务 Dockerfile 。
    build:
      context: . # 构建的路径
      dockerfile: ./restful/user/Dockerfile # 指定 Dockerfile 文件
  1. 最后就是 Docker 命令问题,启动多个服务和修改某个服务需要重启但又不想重启基础环境配置。
# 启动所有服务
# -f 指定docker-compose文件
docker compose -f compose-base.yaml -f compose.yaml up --build

# 启动指定服务
# --build server 表示重新构建服务,server 表示服务名称
# --no-deps 表示不启动依赖服务
docker compose -f compose-base.yaml -f compose.yaml up --build server --no-deps 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant