2

I'm using docker and docker-compose to compose a service which is a combination of several others. As the inner services are serving each other, there's a predefined priority by which they must be started. The easiest way I found to do this, is to use a startup script to run each service (in their designated container) to check for the prerequisites before actually running the container's service. Here's what I'm using right now:

#!/bin/sh

cd /external-indexer

echo "Waitng for RabbitMQ on $RMQ_HOST:$RMQ_PORT"
until curl http://$RMQ_HOST:$RMQ_PORT/  > /dev/null 2>&1
do
  echo "$(date) - RabbitMQ is not ready yet"
  sleep 1
done
echo "$(date) - RabbitMQ is ready"

echo "Waitng for PostgreSQL on $PG_HOST:$PG_PORT"
until wget $PG_HOST:$PG_PORT -t 1 2>&1 | grep " connected"
do
    echo "$(date) - PostgreSQL is not ready yet"
    sleep 1
done
echo "$(date) - PostgreSQL is ready"

./run-service

As you can see here, I'm waiting for two other services (RabbitMQ and PostgreSQL) before starting the current service. And it works. But the thing is that PostgreSQL does not provide an HTTP protocol and the only way I could manage to find if it is serving was to look for the connected in the response provided by wget program.

I was wondering if there's a legitimate way to do this which works regardless of the protocol spoken on the port. And please remeber, I'm not looking for some big service which can orchestrate my whole network. I'm looking for a small program, like the ones named here, which can be found in a container and returns true once connection can be made on a remote port.

1 Answer 1

1

Telnet is often used to quickly check connectivity.

telnet <servername> <port number>

You should get a message about being connected if the port is accessible, like so:

$ telnet www.google.com 80
Trying 216.58.195.132...
Connected to www.google.com.
Escape character is '^]'.

There is also netcat, which is another very simple networking tool that can make arbitrary TCP and UDP connections.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .