docker - 如何仅在另一个事件镜像完成任务后才运行docker镜像?

标签 docker docker-compose dockerfile

我有以下配置:

services:
  db:
    image: mysql:5.6
    command: --default-authentication-plugin=mysql_native_password --sql-mode=""
    volumes:
      - ./schema:/docker-entrypoint-initdb.d
    ports:
      - 3309:3306
    environment:
      MYSQL_ROOT_PASSWORD: test
      MYSQL_DATABASE: test    

  migration-tool:
        depends_on:
          - db
        build:
            context: ../MigrationTool.MigrationTool/
            dockerfile: Dockerfile.migrate
db服务在数据库中执行了一些长时间运行的插入操作,但是迁移工具服务也将要在db服务镜像上创建一个数据库(带有插入操作),这将导致迁移工具服务中出现一些异常,确切地说是mysql db image拒绝来自migraton-tool图像的连接。
仅在完成db服务插入后,一切正常,但此操作通常需要几分钟。
我只需要在第一张图片中完成所有插入操作后,才需要控制第二张图片(migration-tool)的开始的方法。或者,也许对于上述情况有更好的解决方案。谢谢。

最佳答案

您可以创建一个healthcheck,例如:

healthcheck:
  test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
  interval: 1m30s
  timeout: 10s
  retries: 3
  start_period: 40s

关于docker - 如何仅在另一个事件镜像完成任务后才运行docker镜像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64388467/

相关文章:

python-3.x - 为什么 Azure Function V2 不支持少数 python 包?

Docker 由两个文件组成

docker - Docker Swarm-仅在本地环境中使用mongod服务

docker - 如何使用 Docker Compose 连接到 Redis 容器?

docker - docker-compose 中不同 docker 服务之间的通信

laravel - 将 Laravel .env 变量传递给 Dockerfile

docker - 无法将 github 公共(public)存储库克隆到 Dockerfile 的运行顺序中

git - 远程容器 - 无法通过 SSH key 使用 Git

c# - centos 8 中 docker build net core 5.0 报错 NET SDK is not installed

azure - docker - Azure 容器实例 - 如何使我的容器可从外部访问和识别?