-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Document suggested workaround for no connections until DB init complete #81
Comments
+1, seems sane to me to add examples of how to accomplish this reasonably
|
Take this back, not working now... Leaving things below for reference. I just worked around this, then found this issue. My use case was for running tests, so I did this:
Where entrypoint.sh is the same as before, except has I'm sure there is a better solution, but the referenced ones seem hacky as well. |
Have the same problem with a docker compose file which includes a mysql container. Other containers are much faster to start and before mysql is even initialised, they fail because DB is not accessible. |
Like @yosifkit said you can start mysql first. A clean way to do this is to use a separate docker-compose for dbs and use the external link feature of compose to link to the db container (https://docs.docker.com/compose/yml/#external-links). |
as I have only one DB container, for now I just start that one and then do On Wed, 12 Aug 2015 at 04:32 Bryce Reynolds notifications@github.com
|
Big usability impairment for docker-compose IMO! A bit disappointed as this common use-case needs workarounds. If it can't be fixed, I agree documentation is needed. @yosifkit can you elaborate?
And, would this be a clean workaround? From MariaDB:
https://mariadb.com/kb/en/mariadb-enterprise/mariadb-enterprise-in-docker/#my_wait_socket |
As I understand it, compose will report a container as ready as soon as it starts (so when the entrypoint script starts executing), so the MariaDB workaround would still need to be added to the container that depends on the database, similar to other ways to check if the database is up and running. Some way for the database (or any container) to tell Docker they're "ready" would be nice :) |
True. See also: docker/compose#374 |
Something like the following: app:
image: wordpress
links:
- db:mysql
ports:
- 8080:80
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: example
# this is the important part:
volumes:
- ./mysql/:/var/lib/mysql Then start up just the mysql container $ docker-compose up db
........... wait for it to initialize and be ready for network connections:
db_1 | 2015-10-20 23:00:11 1 [Note] Server hostname (bind-address): '*'; port: 3306
db_1 | 2015-10-20 23:00:11 1 [Note] IPv6 is available.
db_1 | 2015-10-20 23:00:11 1 [Note] - '::' resolves to '::';
db_1 | 2015-10-20 23:00:11 1 [Note] Server socket created on IP: '::'.
db_1 | 2015-10-20 23:00:11 1 [Warning] 'proxies_priv' entry '@ root@04463714990e' ignored in --skip-name-resolve mode.
db_1 | 2015-10-20 23:00:11 1 [Note] Event Scheduler: Loaded 0 events
db_1 | 2015-10-20 23:00:11 1 [Note] mysqld: ready for connections.
db_1 | Version: '5.6.27' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
^CGracefully stopping... (press Ctrl+C again to force)
Stopping wordpress_db_1... done Now So this works when both are stopped and the app takes longer to start than MySQL. I think the best solution is to create your apps with tolerance on waiting for the database to be available and a configurable timeout for failure. It should be similar to the way that you make one "microservice" tolerant of another "microservice" that is unresponsive. Technically this has always been an issue in database connected applications, but we have usually either already had a database running (on our host for dev usage), or had the system admin spin one up beforehand. |
Adding something like the nc-example plus maybe the suggestion of starting the database container separately to docs would be good, I think. |
+1 for |
I didn't use |
I've started to use https://github.com/vishnubob/wait-for-it for this. Pulling this in as a Git subtree is easy, and I can then map it into the containers that need to wait for the DB to be up. In the container, I run a script as the /usr/local/wait-for-it/wait-for-it.sh db:3306 Works great for me! |
@nwinkler I used |
I had success scanning the docker logs:
|
@micahjsmith interesting solution! I would caution that it's going to cause problems if you ever use |
See also the discussion in #2 -- I'm going to close, since there isn't really a generic way we can solve this cleanly, but I think the existing discussion will serve as a good reference point for future travelers! |
Hi! This issue was about collecting together the various options and documenting them in the README (which would be more discoverable than having to find these issues) - so still seems actionable? Failing that, perhaps even linking to those issues from the README section linked in the OP might be a good stop-gap? |
I think my main concern with doing anything here is that this is really a generic Docker issue, not something specific to MySQL -- any container which needs to talk to another container (or relies on another container) requires similar consideration and care, so it feels wrong to document this in the context of the MySQL image. 😕 |
Redundance is good for humans, despite the once and only once pattern for
software.
Reopening and only closing if the README got updated a little with pointers
to any case sounds good to me.
…On 28 December 2017 at 18:54, Tianon Gravi ***@***.***> wrote:
I think my main concern with doing anything here is that this is really a
generic Docker issue, not something specific to MySQL -- any container
which needs to talk to another container (or relies on another container)
requires similar consideration and care, so it feels wrong to document this
in the context of the MySQL image. 😕
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#81 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABka_FMrUsMMYxh9Lq4CyQRQvj-AdIq-ks5tE9XZgaJpZM4FH8M7>
.
|
Yeah, I suppose having a tad bit more than what we had there seems reasonable, see docker-library/docs#1106. |
When using docker-compose, even if one service is marked as depending on the mysql service, the first service is started before the initial DB init is complete - and it is then unable to initially connect to the mysql service, causing errors:
https://github.com/docker-library/docs/tree/master/mysql#no-connections-until-mysql-init-completes
It would be good to add to the documentation at that link with a couple of suggested workarounds, eg using
mysqladmin ping
(example) ornc
(for when mysqladmin is not available; slightly over-complex example) - to save everyone from having to reinvent the wheel :-)The text was updated successfully, but these errors were encountered: