You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is there a way to delay container startup to support dependant services with a longer startup time #374
I have a MySQL container that takes a little time to start up as it needs to import data.
I have an Alfresco container that depends upon the MySQL container.
At the moment, when I use fig, the Alfresco service inside the Alfresco container fails when it attempts to connect to the MySQL container... ostensibly because the MySQL service is not yet listening.
Is there a way to handle this kind of issue in Fig?
At work we wrap our dependent services in a script that check if the link is up yet. I know one of my colleagues would be interested in this too! Personally I feel it's a container-level concern to wait for services to be available, but I may be wrong :)
It'd be handy to have an entrypoint script that loops over all of the links and waits until they're working before starting the command passed to it.
This should be built in to Docker itself, but the solution is a way off. A container shouldn't be considered started until the link it exposes has opened.
Reacted by Justin Aiken, Maria Yancheva, Jeanneret Cedric, Kip Obenauf, Aliaksandr Harbunou, Ross Patterson, Yevgeniy, mehere, Jonas Cosandey, Kamil Dziedzic and 26 more
Reacted by Misael Cureño and Carlos DaLomba
Reacted by Misael Cureño, Carlos DaLomba and DaveTSG
Reacted by BlueT - Matthew Lien - 練喆明, Alan Gabriel Bem, Sebastian Dahlgren, Harshal Shah, Ben Hearsum (he/him), Erik, Victor Pereira, Kamil Dziedzic, Andrew Spiers, Zi and 8 more
Yeah, I'd be interested in something like this - meant to post about it earlier.
The smallest impact pattern I can think of that would fix this usecase for us would be to be the following:
Add "wait" as a new key in fig.yml, with similar value semantics as link. Docker would treat this as a pre-requisite and wait until this container has exited prior to carrying on.
On running app, it will start up all the link containers, then run the wait container and only progress to the actual app container once the wait container (initdb) has exited. initdb would run a script that waits for the database to be available, then runs any initialisations/migrations/whatever, then exits.
That's my thoughts, anyway.
Reacted by Erin Dachtler, Julian Reyes Escrigas, Mikhail Kuklin, Ben Sjoberg, Marek Kowalski, Ben Hearsum (he/him), Andriy Tkach, Aditya Mittal, Andrew Kravchuk, Jonas and 73 more
Reacted by Julian Reyes Escrigas, Victor, Kujiy, Echo Xu, tomstark, Saucistophe, Jamtastic, Prakash, Carlos DaLomba and Kosmas Papadatos
Reacted by Mohamed Nabil Himri, Kujiy, Nicolas Coutin, Esteban Zacharzewski, Echo Xu, Mikael Lepistö, Karl, Saucistophe, Aaron, Adjamilton Junior and 7 more
I am writing wrapper scripts as entrypoints to synchronise at the moment, not sure if having a mechanism in fig is wise if you have other targets for your containers that perform orchestration a different way. Seems very application specific to me, as such the responsibility of the containers doing the work.
After some thought and experimentation I do kind of agree with this.
As such an application I'm building basically has a synchronous
waitfor(host, port) function that lets me waits for services the application
is depending on (either detected via environment or explicitly
configuration via cli options).
On Fri, Aug 22, 2014 at 6:34 PM, Mark Stuart [email protected]
wrote:
I am writing wrapper scripts as entrypoints to synchronise at the moment,
not sure if having a mechanism in fig is wise if you have other targets for
your containers that perform orchestration a different way. Seems very
application specific to me as such the responsibility of the containers
doing the work.
—
Reply to this email directly or view it on GitHub #374 (comment).
Yes some basic "depend's on" neeeded here...
so if you have 20 container, you just wan't to run fig up and everything starts with correct order...
However it also have some timeout option or other failure catching mechanisms
#!/bin/sh
postgres_host=$1
postgres_port=$2
shift 2
cmd="$@"
# wait for the postgres docker to be running
while ! pg_isready -h $postgres_host -p $postgres_port -q -U postgres; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up - executing command"
# run the command
exec $cmd
Reacted by ë, Karlis, hlovdal, Carlos DaLomba and Graham Williamson
@slava-nikulin custom entrypoint is a common practice, it is almost the only (docker native) way how you can define and check all conditions you need before staring your app in a container.
Truth is there was a lot of debate and I think the 2.x support for the conditional support to natively integrate with health checks and order the startup was a much needed support. Docker does not support local pod of containers natively and when it does it will have to support something similar again just like kubernetes for example provides the semantics.
Docker 3.x is a series to bring swarm support into compose and hence bunch of options has been dropped keeping the distributed nature in mind.
2.x series preserves the original compose/local topology features.
Docker has to figure out how to merge these 2 versions because forcing swarm onto compose by reducing feature set of compose is not a welcome direction.
On May 10, 2017, at 8:15 PM, Slava Nikulin ***@***.***> wrote:
Unfortunatelly, condition is not supported anymore in v3. Here is workaround, that I've found:
website:
depends_on:
- 'postgres'
build: .
ports:
- '3000'
volumes:
- '.:/news_app'
- 'bundle_data:/bundle'
entrypoint: ./wait-for-postgres.sh postgres 5432
postgres:
image: 'postgres:9.6.2'
ports:
- '5432'
wait-for-postgres.sh:
#!/bin/sh
postgres_host=$1
postgres_port=$2
cmd="$@"
# wait for the postgres docker to be running
while ! pg_isready -h $postgres_host -p $postgres_port -q -U postgres; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up - executing command"
# run the command
exec $cmd
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
Reacted by Leo Gallucci, Ain Tohvri, Jean-Louis Jouannic, phil swenson, r900, Yue Ni, Nicole, ChristianEspinoza, Pierre de Soultrait, Denis N. Antonioli and 32 more
#!/bin/shset -eu
docker volume create --name=gql-sync
echo"Building docker containers"
docker-compose build
echo"Running tests inside docker container"
docker-compose up -d pubsub
docker-compose up -d mongo
docker-compose up -d botms
docker-compose up -d events
docker-compose up -d identity
docker-compose up -d importer
docker-compose run status
docker-compose run testing
exit$?
// status.sh
#!/bin/shset -eu pipefail
echo"Attempting to connect to bots"until$(nc -zv botms 3000);doprintf'.'
sleep 5
doneecho"Attempting to connect to events"until$(nc -zv events 3000);doprintf'.'
sleep 5
doneecho"Attempting to connect to identity"until$(nc -zv identity 3000);doprintf'.'
sleep 5
doneecho"Attempting to connect to importer"until$(nc -zv importer 8080);doprintf'.'
sleep 5
doneecho"Was able to connect to all"exit 0
Reacted by Nicole, Karl Pietrzak, Carter Harwood, Kevin Smith, Oleh Kachynskyi, Davi Medeiros, chaicode88, Charlie, Donovan, Daniel Rodriguez del Villar Trimarchi and 4 more
I have a similar problem but a bit different. I have to wait for MongoDB to start and initialize a replica set.
Im doing all of the procedure in docker. i.e. creating and authentication replica set. But I have another python script in which I have to connect to the primary node of the replica set. I'm getting an error there.
docker-compose.txt Dockerfile.txt
and in the python script im trying to do something like this for x in range(1, 4): client = MongoClient(host='node' + str(x), port=27017, username='admin', password='password') if client.is_primary: print('the client.address is: ' + str(client.address)) print(dbName) print(collectionName) break
Am having difficulty in doing so, anyone has any idea?
@patrickml If I don't use docker compose, How I you do it with Dockerfile?
I need 'cqlsh' to execute my build_all.cql. However, 'cqlsh' is not ready...have to wait for 60 seconds to be ready.
WORKDIR /docker/cms/db-scripts-2.1.33.2/
RUN cqlsh -f build_all.cql
USER dse
=============
Step 8/9 : RUN cqlsh -f build_all.cql
---> Running in 08c8a854ebf4
Connection error: ('Unable to connect to any servers', {'127.0.0.1': error(111, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})
The command '/bin/sh -c cqlsh -f build_all.cql' returned a non-zero code: 1
Activity
d11wtq commentedon Aug 4, 2014
At work we wrap our dependent services in a script that check if the link is up yet. I know one of my colleagues would be interested in this too! Personally I feel it's a container-level concern to wait for services to be available, but I may be wrong :)
nubs commentedon Aug 4, 2014
We do the same thing with wrapping. You can see an example here: https://github.com/dominionenterprises/tol-api-php/blob/master/tests/provisioning/set-env.sh
bfirsh commentedon Aug 4, 2014
It'd be handy to have an entrypoint script that loops over all of the links and waits until they're working before starting the command passed to it.
This should be built in to Docker itself, but the solution is a way off. A container shouldn't be considered started until the link it exposes has opened.
dancrumb commentedon Aug 4, 2014
@bfirsh that's more than I was imagining, but would be excellent.
I think that's exactly what people need.
For now, I'll be using a variation on https://github.com/aanand/docker-wait
silarsis commentedon Aug 4, 2014
Yeah, I'd be interested in something like this - meant to post about it earlier.
The smallest impact pattern I can think of that would fix this usecase for us would be to be the following:
Add "wait" as a new key in fig.yml, with similar value semantics as link. Docker would treat this as a pre-requisite and wait until this container has exited prior to carrying on.
So, my docker file would look something like:
On running app, it will start up all the link containers, then run the wait container and only progress to the actual app container once the wait container (initdb) has exited. initdb would run a script that waits for the database to be available, then runs any initialisations/migrations/whatever, then exits.
That's my thoughts, anyway.
dnephin commentedon Aug 5, 2014
(revised, see below)
dsyer commentedon Aug 14, 2014
+1 here too. It's not very appealing to have to do this in the commands themselves.
jcalazan commentedon Aug 15, 2014
+1 as well. Just ran into this issue. Great tool btw, makes my life so much easier!
arruda commentedon Aug 16, 2014
+1 would be great to have this.
prologic commentedon Aug 19, 2014
+1 also. Recently run into the same set of problems
chymian commentedon Aug 19, 2014
+1 also. any statement from dockerguys?
codeitagile commentedon Aug 22, 2014
I am writing wrapper scripts as entrypoints to synchronise at the moment, not sure if having a mechanism in fig is wise if you have other targets for your containers that perform orchestration a different way. Seems very application specific to me, as such the responsibility of the containers doing the work.
prologic commentedon Aug 22, 2014
After some thought and experimentation I do kind of agree with this.
As such an application I'm building basically has a synchronous
waitfor(host, port) function that lets me waits for services the application
is depending on (either detected via environment or explicitly
configuration via cli options).
cheers
James
James Mills / prologic
E: [email protected]
W: prologic.shortcircuit.net.au
On Fri, Aug 22, 2014 at 6:34 PM, Mark Stuart [email protected]
wrote:
shuron commentedon Aug 31, 2014
Yes some basic "depend's on" neeeded here...
so if you have 20 container, you just wan't to run fig up and everything starts with correct order...
However it also have some timeout option or other failure catching mechanisms
ahknight commentedon Oct 23, 2014
Another +1 here. I have Postgres taking longer than Django to start so the DB isn't there for the migration command without hackery.
302 remaining items
slava-nikulin commentedon May 11, 2017
Unfortunatelly, condition is not supported anymore in v3. Here is workaround, that I've found:
wait-for-postgres.sh:
riuvshin commentedon May 11, 2017
@slava-nikulin custom entrypoint is a common practice, it is almost the only (docker native) way how you can define and check all conditions you need before staring your app in a container.
mbdas commentedon May 11, 2017
patrickml commentedon Jun 22, 2017
I was able to do something like this
// start.sh
// status.sh
// in my docker compose file
usamaB commentedon Oct 30, 2017
I have a similar problem but a bit different. I have to wait for MongoDB to start and initialize a replica set.
Im doing all of the procedure in docker. i.e. creating and authentication replica set. But I have another python script in which I have to connect to the primary node of the replica set. I'm getting an error there.
docker-compose.txt
Dockerfile.txt
and in the python script im trying to do something like this
for x in range(1, 4): client = MongoClient(host='node' + str(x), port=27017, username='admin', password='password') if client.is_primary: print('the client.address is: ' + str(client.address)) print(dbName) print(collectionName) breakAm having difficulty in doing so, anyone has any idea?
chaicode88 commentedon Apr 26, 2018
@patrickml If I don't use docker compose, How I you do it with Dockerfile?
I need 'cqlsh' to execute my build_all.cql. However, 'cqlsh' is not ready...have to wait for 60 seconds to be ready.
cat Dockerfile
FROM store/datastax/dse-server:5.1.8
USER root
RUN apt-get update
RUN apt-get install -y vim
ADD db-scripts-2.1.33.2-RFT-01.tar /docker/cms/
COPY entrypoint.sh /entrypoint.sh
WORKDIR /docker/cms/db-scripts-2.1.33.2/
RUN cqlsh -f build_all.cql
USER dse
=============
Step 8/9 : RUN cqlsh -f build_all.cql
---> Running in 08c8a854ebf4
Connection error: ('Unable to connect to any servers', {'127.0.0.1': error(111, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})
The command '/bin/sh -c cqlsh -f build_all.cql' returned a non-zero code: 1
use fix for docker/compose#374
Remove db_clean service from docker-compose.yml
Wait 3 seconds to let server to start
henroFall commentedon Oct 27, 2020
Requires= var-lib-libvirt.mount var-lib-libvirt-images-ram.mount
Lunar2kPS commentedon May 24, 2022
In case anyone comes back to this years later, read this wonderful page from the Docker Compose docs for updated info!
skorokithakis commentedon May 24, 2022
There are also health checks built in now, which solve the problem better.
Wait 3 seconds to let server to start
Wait 3 seconds to let server to start