Giter Site home page Giter Site logo

dockerize-compose-demo's Introduction

Dockerize Demo - Wait for containers

Simple Docker Compose setup: front-end API that takes 5 seconds to start up, and a test harness that hits the API 100 times, failing if it receives any non-20x response codes.

Running

Failing Example

git co fail
docker-compose up

The test should fail with something like:

test_1 | web_test.go:46: Error not expected: Get http://api/: dial tcp 172.17.0.3:80: getsockopt: connection refused

This is because Compose knows the container has started, but not the service within it.

Passing Example

Using Dockerize, we can ensure the tests don't run until the dependent API is up and running:

git co dockerize
docker-compose up

Background

It is common when using tools like Docker Compose to depend on services in other linked containers, however oftentimes relying on links is not enough - whilst the container itself may have started, the service(s) within it may not yet be ready - resulting in shell script hacks to work around race conditions.

This PR gives dockerize the ability to wait for services on a specified protocol (tcp, tcp4, tcp6, http, and https) before starting the main application:

dockerize -wait tcp://web:80 -wait http://web:80

I've found this to be particularly useful when using Docker Compose as a test harness, where one of the containers needs to test another. Instead of netcating my way around the problem, I can just wrap the command using dockerize.

References / Related reading

dockerize-compose-demo's People

Contributors

mefellows avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

40a myang32 miyazak8

dockerize-compose-demo's Issues

Branchs dockerize and fail

Nice demo, but following your readme this project need branchs fail and dockerize and the repo don't have this branchs, i think that branch fail up compose without dockerize and branch dockerize up compose with dockerize wait..

what do you think that instead use branch, project use one Makefile with two targets?

i could make this change if you want..

docker-compose command override using dockerize results in Visual Studio error running solution "Can not find the container with the name starting with"

This works great outside of Visual Studio.

However, running a docker-compose project which tries to use command override in the docker-compose.override.yml to start the container using dockerize, Visual Studio results in Can not find the container with the name starting with 'MyProject' errors because the container does not have a status of running as dockerize is waiting to start it.

docker-compose.override.yml

command: ["./dockerize", "-wait", "tcp://mydatabase:1433", "-wait-retry-interval", "20s", "-timeout", "3m", "dotnet", "MyProject.dll"]

Visual Studio output

========== Debugging ==========
docker ps --filter "status=running" --filter "label=com.docker.compose.service" --filter "name=^/MyProject$" --format {{.ID}} -n 1

Removing the command override from the docker-compose.override.yml file and moving it to inside the Dockerfile seems to let Visual Studio work, but doesn't seem to honor the dockerize command and just goes into the dotnet cmd. Not being able to override the CMD from the docker-compose.override.yml is problematic in trying to change the name of the target to wait on per environment.

Dockerfile

COPY ["dockerize", "./"]
RUN chmod +x ./dockerize
CMD ["./dockerize", "-wait", "tcp://mydatabase:1433", "-wait-retry-interval", "20s", "-timeout", "3m", "dotnet", "MyProject.dll"]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.