{"id":13437336,"url":"https://github.com/ufoscout/docker-compose-wait","last_synced_at":"2025-05-14T11:11:06.747Z","repository":{"id":40548247,"uuid":"75212086","full_name":"ufoscout/docker-compose-wait","owner":"ufoscout","description":"A simple script to wait for other docker images to be started while using docker-compose (or Kubernetes or docker stack or whatever)","archived":false,"fork":false,"pushed_at":"2025-02-22T14:57:41.000Z","size":123,"stargazers_count":1660,"open_issues_count":2,"forks_count":149,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-11T23:55:30.976Z","etag":null,"topics":["containers","docker","docker-images","dockerfile","kubernetes","sleep","synchronization","wait"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ufoscout.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-30T17:48:49.000Z","updated_at":"2025-04-09T05:27:10.000Z","dependencies_parsed_at":"2022-08-09T22:50:45.679Z","dependency_job_id":"cd759b40-c92f-45f2-8853-6515b87da428","html_url":"https://github.com/ufoscout/docker-compose-wait","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ufoscout%2Fdocker-compose-wait","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ufoscout%2Fdocker-compose-wait/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ufoscout%2Fdocker-compose-wait/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ufoscout%2Fdocker-compose-wait/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ufoscout","download_url":"https://codeload.github.com/ufoscout/docker-compose-wait/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248497812,"owners_count":21113984,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["containers","docker","docker-images","dockerfile","kubernetes","sleep","synchronization","wait"],"created_at":"2024-07-31T03:00:56.080Z","updated_at":"2025-04-11T23:55:35.005Z","avatar_url":"https://github.com/ufoscout.png","language":"Rust","readme":"# docker-compose-wait\n\n![Build Status](https://github.com/ufoscout/docker-compose-wait/actions/workflows/build_and_test.yml/badge.svg)\n[![codecov](https://codecov.io/gh/ufoscout/docker-compose-wait/branch/master/graph/badge.svg)](https://codecov.io/gh/ufoscout/docker-compose-wait)\n\nA small command-line utility to wait for other docker images to be started while using docker-compose (or Kubernetes or docker stack or whatever).\n\nIt permits waiting for:\n- a fixed amount of seconds\n- until a TCP port is open on a target image\n- until a file or directory is present on the local filesystem\n\n## Usage\n\nThis utility should be used in the docker build process and launched before your application starts.\n\nFor 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:\n\n```dockerfile\n## Use whatever base image\nFROM alpine\n\n## Add the wait script to the image\nCOPY --from=ghcr.io/ufoscout/docker-compose-wait:latest /wait /wait\n\n## Otherwise you can directly download the executable from github releases. E.g.:\n#  ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.11.0/wait /wait\n#  RUN chmod +x /wait\n\n## Add your application to the docker image\nADD MySuperApp.sh /MySuperApp.sh\n\n## Launch the wait tool and then your application\nCMD /wait \u0026\u0026 /MySuperApp.sh\n```\n\nDone! the image is ready.\n\nNow let's modify the docker-compose.yml file:\n\n```yml\nversion: \"3\"\n\nservices:\n  mongo:\n    image: mongo:3.4\n    hostname: mongo\n    ports:\n      - \"27017:27017\"\n\n  postgres:\n    image: \"postgres:9.4\"\n    hostname: postgres\n    ports:\n      - \"5432:5432\"\n\n  mysql:\n    image: \"mysql:5.7\"\n    hostname: mysql\n    ports:\n      - \"3306:3306\"\n\n  mySuperApp:\n    image: \"mySuperApp:latest\"\n    hostname: mySuperApp\n    environment:\n      WAIT_HOSTS: postgres:5432, mysql:3306, mongo:27017\n```\n\nWhen 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.\nThe WAIT_HOSTS environment variable is not mandatory, if not declared, the script executes without waiting.\n\nIf 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:\n\n```bash\ncommand: sh -c \"/wait \u0026\u0026 /MySuperApp.sh\"\n```\n\nThis is discussed further [here](https://stackoverflow.com/questions/30063907/using-docker-compose-how-to-execute-multiple-commands) and [here](https://github.com/docker/compose/issues/2033).\n\n## Usage in images that do not have a shell\n\nWhen using [distroless](https://github.com/GoogleContainerTools/distroless) or building images [`FROM scratch`](https://docs.docker.com/develop/develop-images/baseimages/#create-a-simple-parent-image-using-scratch), it is common to not have `sh` available. In this case, it is necessary to [specify the command for wait to run explicitly](#additional-configuration-options). The invoked command will be invoked with any arguments configured for it and will completely replace the `wait` process in your container via a syscall to [`exec`](https://man7.org/linux/man-pages/man3/exec.3.html). Because there is no shell to expand arguments in this case, `wait` must be the `ENTRYPOINT` for the container and has to be specified in [the exec form](https://docs.docker.com/engine/reference/builder/#exec-form-entrypoint-example). Note that because there is no shell to perform expansion, arguments like `*` must be interpreted by the program that receives them.\n\n```dockerfile\nFROM golang\n\nCOPY myApp /app\nWORKDIR /app\nRUN go build -o /myApp -ldflags '-s -w -extldflags -static' ./...\n\n## ----------------\n\nFROM scratch\n\nCOPY --from=ghcr.io/ufoscout/docker-compose-wait:latest /wait /wait\n\nCOPY --from=0 /myApp /myApp\nENV WAIT_COMMAND=\"/myApp arg1 argN...\"\nENTRYPOINT [\"/wait\"]\n```\n\n## Additional configuration options\n\nThe behaviour of the wait utility can be configured with the following environment variables:\n\n- _WAIT_LOGGER_LEVEL_ : the output logger level. Valid values are: _debug_, _info_, _error_, _off_. the default is _debug_. \n- _WAIT_HOSTS_: comma-separated list of pairs host:port for which you want to wait.\n- _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.\n- _WAIT_COMMAND_: command and arguments to run once waiting completes. The invoked command will completely replace the `wait` process. The default is none.\n- _WAIT_TIMEOUT_: max number of seconds to wait for all the hosts/paths to be available before failure. The default is 30 seconds.\n- _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.\n- _WAIT_BEFORE_: number of seconds to wait (sleep) before start checking for the hosts/paths availability\n- _WAIT_AFTER_: number of seconds to wait (sleep) once all the hosts/paths are available\n- _WAIT_SLEEP_INTERVAL_: number of seconds to sleep between retries. The default is 1 second.\n\n\n## Supported architectures\n\nFrom release 2.11.0, the following executables are available for download:\n- _wait_: This is the executable intended for Linux x64 systems\n- *wait_x86_64*: This is the very same executable than _wait_\n- *wait_aarch64*: This is the executable to be used for aarch64 architectures\n- *wait_arm7*: This is the executable to be used for arm7 architectures\n\nAll executables are built with [MUSL](https://www.musl-libc.org/) for maximum portability.\n\nTo use any of these executables, simply replace the executable name in the download link:\nhttps://github.com/ufoscout/docker-compose-wait/releases/download/{{VERSION}}/{{executable_name}}\n\n\n## Docker images\n\nOfficial docker images based on `scratch` can be found here:\nhttps://github.com/users/ufoscout/packages/container/package/docker-compose-wait\n\n\n## Using on other systems\n\nThe simplest way of getting the _wait_ executable is to download it from\n\n[https://github.com/ufoscout/docker-compose-wait/releases/download/{{VERSION}}/wait](https://github.com/ufoscout/docker-compose-wait/releases/download/{{VERSION}}/wait)\n\nor to use one of the pre-built docker images.\n\nIf you need it for an architecture for which a pre-built file is not available, you should clone this repository and build it for your target.\n\nAs it has no external dependencies, an being written in the mighty [rust](https://www.rust-lang.org)\nprogramming language, the build process is just a simple `cargo build --release`\n(well... of course you need to install the rust compiler before...)\n\nFor everything involving cross-compilation, you should take a look at [Cross](https://github.com/rust-embedded/cross).\n\nFor example, to build for a **raspberry pi**, everything you have to do is:\n\n1. Install the latest stable rust toolchain using rustup\n2. Correctly configure Docker on your machine\n3. Open a terminal and type:\n\n```bash\ncargo install cross\ncross build --target=armv7-unknown-linux-musleabihf --release\n```\n\nUse your shiny new executable on your raspberry device!\n\n## Notes\n\nThis utility was explicitly written to be used with docker-compose; however, it can be used everywhere since it has no dependencies on docker.\n","funding_links":[],"categories":["HarmonyOS","Rust","kubernetes","Docker-Tools"],"sub_categories":["Windows Manager"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fufoscout%2Fdocker-compose-wait","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fufoscout%2Fdocker-compose-wait","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fufoscout%2Fdocker-compose-wait/lists"}