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

Allow dockerize to wait for network dependencies before main command #23

Merged
merged 1 commit into from
Jan 25, 2016

Conversation

mefellows
Copy link
Contributor

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://db:5432 -wait http://web:80 -timeout 10s somecommand

Note the timeout is optional and defaults to 10s.

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.

I also fixed a few minor grammatical/spelling mistakes.

Related links:

go func() {
defer wg.Done()
for {
_, err := http.Get(u.String())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this should check to make sure a 200 response is returned. What if a 404 or 500 is returned by the dependency?

You an also specify a timeout using a custom http.Client and/or Transport.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I originally interpreted the err to mean non-20x. This is fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RE: timeout. I did consider this, but felt the added complexity wasn't going to give us much given we check the timeout of the entire set of dependencies anyway. Let me know if you would prefer it the other way.

@thaJeztah
Copy link

ping @jwilder looks like this PR has been updated; ptal 👍

jwilder added a commit that referenced this pull request Jan 25, 2016
Allow dockerize to wait for network dependencies before main command
@jwilder jwilder merged commit a2e1043 into jwilder:master Jan 25, 2016
@mefellows mefellows deleted the wait-for-dependencies branch January 25, 2016 05:18
@mefellows
Copy link
Contributor Author

Thanks! 🎉

@jwilder
Copy link
Owner

jwilder commented Jan 25, 2016

Thanks @mefellows! Nice feature idea.

@mefellows
Copy link
Contributor Author

No worries at all - do I need to do anything to get this 'released' or will you look after that in due course?

@jwilder
Copy link
Owner

jwilder commented Jan 25, 2016

@mefellows I just created a new v0.1.0 release.

@mefellows
Copy link
Contributor Author

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants