当前位置: 首页 > 软件库 > 云计算 > 云原生 >

docker-compose-wait

授权协议 Apache-2.0 License
开发语言 Google Go
所属分类 云计算、 云原生
软件类型 开源软件
地区 不详
投 递 者 祝高阳
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

docker-compose-wait

FOSSA Status

A small command-line utility to wait for other docker images to be started while using docker-compose.

It permits waiting for:

  • a fixed amount of seconds
  • until a TCP port is open on a target image
  • until a file or directory is present on the local filesystem

Usage

This utility should be used in the docker build process and launched before your application starts.

For example, your application "MySuperApp" uses MongoDB, Postgres and MySql (wow!) and you want to be sure that, when it starts, all other systems are available, then simply customize your dockerfile this way:

## Use whatever base image
FROM alpine

## Add the wait script to the image
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.9.0/wait /wait
RUN chmod +x /wait

## Add your application to the docker image
ADD MySuperApp.sh /MySuperApp.sh

## Launch the wait tool and then your application
CMD /wait && /MySuperApp.sh

Done! the image is ready.

Now let's modify the docker-compose.yml file:

version: "3"

services:
  mongo:
    image: mongo:3.4
    hostname: mongo
    ports:
      - "27017:27017"

  postgres:
    image: "postgres:9.4"
    hostname: postgres
    ports:
      - "5432:5432"

  mysql:
    image: "mysql:5.7"
    hostname: mysql
    ports:
      - "3306:3306"

  mySuperApp:
    image: "mySuperApp:latest"
    hostname: mySuperApp
    environment:
      WAIT_HOSTS: postgres:5432, mysql:3306, mongo:27017

When docker-compose is started (or Kubernetes or docker stack or whatever), your application will be started only when all the pairs host:port in the WAIT_HOSTS variable are available.The WAIT_HOSTS environment variable is not mandatory, if not declared, the script executes without waiting.

If you want to use the script directly in docker-compose.yml instead of the Dockerfile, please note that the command: configuration option is limited to a single command so you should wrap in a sh call. For example:

command: sh -c "/wait && /MySuperApp.sh"

This is discussed further here and here.

Do note the recommended way of using wait is with the shell operator &&, which implies the requirement of a shell. This introduces a requirement for Docker use where bases images like scratch not offering a shell cannot be used.

Instead the recommendation for base Docker images are ones offering a shell like alpine, debian etc. and if you want to aim for minimalism, evaluate something like: busybox

Additional configuration options

The behaviour of the wait utility can be configured with the following environment variables:

  • WAIT_LOGGER_LEVEL : the output logger level. Valid values are: debug, info, error, off. the default is debug.
  • WAIT_HOSTS: comma-separated list of pairs host:port for which you want to wait.
  • WAIT_PATHS: comma-separated list of paths (i.e. files or directories) on the local filesystem for which you want to wait until they exist.
  • WAIT_TIMEOUT: max number of seconds to wait for all the hosts/paths to be available before failure. The default is 30 seconds.
  • WAIT_HOST_CONNECT_TIMEOUT: The timeout of a single TCP connection to a remote host before attempting a new connection. The default is 5 seconds.
  • WAIT_BEFORE: number of seconds to wait (sleep) before start checking for the hosts/paths availability
  • WAIT_AFTER: number of seconds to wait (sleep) once all the hosts/paths are available
  • WAIT_SLEEP_INTERVAL: number of seconds to sleep between retries. The default is 1 second.

Using on non-linux systems

The simplest way of getting the wait executable is to download it from

https://github.com/ufoscout/docker-compose-wait/releases/download/{{VERSION}}/wait

This is a pre-built executable for Linux x64 systems which are the default ones in Docker.In addition, it is built with MUSL for maximum portability.

If you need it for a different architecture, you should clone this repository and build it for your target.

As it has no external dependencies, an being written in the mighty rustprogramming language, the build process is just a simple cargo build --release(well... of course you need to install the rust compiler before...)

For everything involving cross-compilation, you should take a look at Cross.

For example, to build for a raspberry pi, everything you have to do is:

  1. Install the latest stable rust toolchain using rustup
  2. Correctly configure Docker on your machine
  3. Open a terminal and type:
cargo install cross
cross build --target=armv7-unknown-linux-musleabihf --release

Use your shiny new executable on your raspberry device!

Notes

This utility was explicitly written to be used with docker-compose; however, it can be used everywhere since it has no dependencies on docker.

License

FOSSA Status

  • Docker-compose-使用wait-for-it.sh脚本 1. 微服务编排:nacos+redis+mysql+微服务 编写微服务Dockerfile 生成镜像 # 基础镜像使用java FROM java:8 # 作者 MAINTAINER hsp # VOLUME 指定临时文件目录为/tmp,在主机/var/lib/docker目录下创建了一个临时文件并链接到容器的/tmp VOLU

  • Dockerfile详解与实践 Docker‘s Network Docker-Compose 1、写在最前面 Docker-Compose是Docker官方的开源项目,负责实现对Docker容器集群的快速编排。 docker建议我们每一个容器中只运行一个服务,因为docker容器本身占用资源极少,建议将每个服务单独的分割开来独立部署! 同时部署好多个服务时,使用 Dockerfile 一一构建镜

  • 前言: 参考几篇非常优秀的文章: 不要轻易使用 Alpine 镜像来构建 Docker 镜像,有坑! 两个奇技淫巧,将 Docker 镜像体积减小 99% 听说你的 Docker 镜像比较胖? Docker Compose 配置文件详解 以及非常优秀的开源项目: Gin-Vue-Admin Docker Compose 概述 Compose 是一个用于定义和运行多容器 Docker 应用程序的工具

  • 一、概述 恢复原有wordpress推荐使用宝塔面板,本文介绍配置新的wordpress站点。 二、环境准备 安装Docker # 更新yum yum update -y # 安装Docker yum install docker -y # 安装完成后进行查看 yum list | grep docker # 验证安装(查看版本号) docker -v # 修改镜像源 vim /etc/docke

  • 一、docker-compose介绍 在上一讲中,我们已经介绍了docker的基本操作。这就是为后面的redis集群和mysql集群做准备。但在生产环境中,我们通常使用更规范的docker-compose。 1.1 docker-compose的介绍 Docker Compose是Docker官方提供的一个工具,它可以用于定义和运行多个Docker容器应用程序。使用Docker Compose,你

  • 1.题目部分 使用docker-compose, 创建两个MySQL容器, 满足如下条件: 使用自定义的my.cnf 形成主从复制关系 容器销毁后, 主实例的数据仍保留, 从实例的数据清零销毁 重建两个容器, 主实例沿用之前的数据, 从实例重建数据, 并建立复制 2.解答部分 2.1 docker安装 docker-compose依赖docker环境,需要先安装好docker,本实验环境为在Cen

  • docker docker源码下载 [root@localhost ~]# cd /usr/local/ [root@localhost local]# wget -c http://mirrors.163.com/docker-ce/linux/static/stable/x86_64/docker-20.10.6.tgz 解压 [root@localhost local]# tar -xf

 相关资料
  • 主要内容:实例,Compose 安装,使用,composetest/app.py 文件代码,docker-compose.yml 配置文件,yml 配置指令参考Compose 简介 Compose 是用于定义和运行多容器 Docker 应用程序的工具。通过 Compose,您可以使用 YML 文件来配置应用程序需要的所有服务。然后,使用一个命令,就可以从 YML 文件配置中创建并启动所有服务。 如果你还不了解 YML 文件配置,可以先阅读 YAML 入门教程。 Compose 使用的三个步骤:

  • 使用 Docker Compose,您可以使用一个命令启动本地测试网络。 需求 安装 tendermint 安装 docker 安装 docker-compose 构建 构建 tendermint 二进制文件和可选 tendermint/localnode docker 映像。 注意,二进制文件将被挂载到容器中,因此可以在不重新构建镜像的情况下更新它。 cd $GOPATH/src/github.

  • Docker Compose 是 Docker 官方编排(Orchestration)项目之一,负责快速的部署分布式应用。 本章将介绍 Compose 项目情况以及安装和使用。

  • 在安装 Compose之前,你需要先安装好 Docker 。然后你需要使用 curl 指令来安装 Compose 安装 Docker 首先,你需要安装大于或者等于1compose/.6版本的 Docker 。 MAC OSX 安装指南 Ubuntu 安装指南 其它系统安装指南 安装 Compose 运行下边的命令来安装 Compose: curl -L https://githubcompose/

  • 解决多容器的 APP 部署问题。 要从 Dockerfile build image 或从 Dockerhub 拉取或从 Tar export iamge。 要创建多个 container。 要管理多个 container。(启动停止删除) 介绍Docker Compose 通过一个 yml 文件定义多容器的 docker 应用,通过一条命令就可以根据 yml 文件的定义去创建或管理这些容器。 版

  • Docker Compose 是 Docker 编排服务的一部分,Machine 可以让用户在其它平台快速安装Docker,Swarm 可以让 Docker 容器在集群中高效运转,而 Compose 可以让用户在集群中部署分布式应用。简单的说,Docker Compose 属于一个“应用层”的服务,用户可以定义哪个容器组运行哪个应用,它支持动态改变应用,并在需要时扩展。 使用Compose的第一步