This page discusses how to control startup order using docker-compose. It recommends three tools: wait-for-it, dockerize or wait-for.
I have struggled to get either wait-for-it or wait-for working as expected, but in this question I'll focus on wait-for.
Each time my docker container starts, it quits with "Operation Timed Out".
Here's my very simple docker file as an example:
FROM ubuntu
COPY ./wait-for.sh /
WORKDIR /
RUN chmod +x ./wait-for.sh
CMD sh -c './wait-for.sh www.eficode.com:80 -- echo "Eficode site is up"'
This should copy the script from the current directory to the root, make it executable and set the run command to execute the script and check the status of the eficode website (example taken from the eficode github page).
I've tried supplying the timeout flag, which does adjust the timeout, but doesn't affect the result. I've also tried running this script as part of a docker-compose command (following the example on the docker-compose documentation page linked above) but, again, with the same result.
What am I doing wrong?
You are missing the netcat
package and nc
isn't available in your example image. Add the following somewhere in your Dockerfile
:
RUN apt-get -q update && apt-get -qy install netcat
As Andy mentions, you need nc
to be installed. You can:
nc
since bash can hit ports directly.nc
. That just means changing the first line to FROM alpine
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With