Skip to content

Wait for linked MySQL server to accept TCP connection before database operation.... #19

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

Closed
wants to merge 1 commit into from
Closed

Conversation

Aagat
Copy link

@Aagat Aagat commented Nov 1, 2014

... Solves issues with fig due to slow MySQL startup. Retries every 5 seconds until MySQL server exposes its TCP port.

…on. Solves issues with fig due to slow MySQL startup.
@Aagat
Copy link
Author

Aagat commented Nov 1, 2014

Related to #17

@Aagat Aagat changed the title Wait for linked MySQL server to open TCP port before database operation.... Wait for linked MySQL server to accept TCP connection before database operation.... Nov 1, 2014
@yosifkit
Copy link
Member

yosifkit commented Nov 3, 2014

This could be a useful feature, but I would want a timeout so that the container will stop if there is no db coming (maybe it died). This could possibly be configurable (MYSQL_WAIT_TIMEOUT or something). Either way, this will definitely need to be documented.

@tianon
Copy link
Member

tianon commented Nov 3, 2014

I'm not sure on this one. This is a fairly general problem that every single application is going to have, and has had since the introduction of networking (Docker just makes it a lot more obvious since it's now trivial to start both of these services at exactly the same moment). At the very least, this feels like something we ought to have some kind of general solution for, possibly in Docker itself. Anything else feels a little bit hacky, IMO.

@yosifkit
Copy link
Member

yosifkit commented Nov 3, 2014

Currently the only other solution is to add --restart=always in the docker run to the dependent service (like wordpress), which seems worse than a retrying nice timeout. I agree that it would be better to be solved in docker since controlling a group of dependent services should definitely be in the future of Docker. Services need a way to tell Docker that they are ready to receive connections on the exposed port or, alternatively, have docker do the checking with something like --ensure-port 3000.

@Aagat
Copy link
Author

Aagat commented Nov 4, 2014

@tianon You're right about having a general solution for this problem as it's fairly common, would be very helpful if docker itself had some option for this. But unfortunately there isn't anything available right now in docker as @yosifkit mentioned and since WP container is useless without MySQL container attached to it, shouldn't ensure MySQL is indeed available before doing anything?Also since we are already ensuring we have MySQL container is attached in our entrypoint script, shouldn't we also ensure that service is actually running before attempting to perform database operation?

@christoph-jerolimov
Copy link

But in my opinion you should switch from while not .. sleep n to if not .. sleep n. The current change request works only if the MySQL database is running on the same host (/dev/... usage). I expect this generic WordPress Docker image should also work the the MySQL instance is running on another host (independent if the database is running in or not in a Docker scenario).

@tianon
Copy link
Member

tianon commented Dec 31, 2014

@jerolimov /dev/tcp/... is actually a bash construction: http://www.linuxjournal.com/content/more-using-bashs-built-devtcp-file-tcpip

@christoph-jerolimov
Copy link

@tianon Oh that is funny. Thanks for the link, really interesting. But keep in mind that a startup process should timeout, or? But in most cases I expect now this would work.

@schmunk42
Copy link

Here's another workaround with a while do bash construct.

@darwingr
Copy link

Are there plans to merge this?
Having a fix via docker would be nice but this fix does seem to work well right now.

@yosifkit
Copy link
Member

While I am not opposed to the idea of Wordpress automatically waiting for mysql to come up, I definitely want it to fail at some timeout instead of trying forever.

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.

6 participants