Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: Why does wait-for always time out?

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).

Image showing the error message

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?

like image 746
Andy F Avatar asked Jun 20 '17 21:06

Andy F


2 Answers

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
like image 88
Andy Shinn Avatar answered Sep 22 '22 01:09

Andy Shinn


As Andy mentions, you need nc to be installed. You can:

  • Manually install the package with his command
  • Switch to wait-for-it that uses bash since your base image is ubuntu. This script doesn't need nc since bash can hit ports directly.
  • Switch to alpine linux if you don't need bash, it ships with nc. That just means changing the first line to FROM alpine.
like image 43
BMitch Avatar answered Sep 22 '22 01:09

BMitch