If I "docker-compose start service" in an interactive terminal (not -it, but a bash running on the host interactively), my service initializes happily.
But if I put that same command in a shell script, it fails.
I suspect the problem is name resolution via /etc/hosts; it seems to work interactively but not in a script for some reason. I want the containers to be able to see the names defined in the host's /etc/hosts. And although I am on Linux Mint 19.1 I need it to work on Windows, Mac and Linux.
Things I've tried that didn't work:
- Adding sleeps - as long as 10 minutes
- Checking for environment variable differences
- Running the command under tcsh instead of bash
- Running the command in a pseudo-tty using /usr/bin/script -c
But if I throw a /bin/bash -i in my script, with an echo that says what command to type, it works!
I'm using:
docker version 18.09.6, build 481bc77
docker-compose version 1.24.0, build 0aa59064
I'd have to get an OK from my management to share more than small snippets of code.
I want the service to start via docker-compose up -d or at least docker-compose start - in a script, for the sake of automation.
The error message inside the container (from docker logs -f service) looks like: elasticsearch.exceptions.ConnectionTimeout: ConnectionTimeout caused by - ReadTimeoutError(HTTPConnectionPool(host=u'elasticsearch', port=9200): Read timed out. (read timeout=10))
I sometimes see a high load in elasticsearch, which seems a bit odd. By high I mean as high as 490% on an 8 core (probably counting hyperthreading). More commonly it's down around 5-15%.
Here's an SSCCE:
#!/bin/bash
set -eu
set -o pipefail
set -x
docker stop elasticsearch || true
docker-compose start elasticsearch
# Give elasticsearch some time to come up.
# Normally I use a small REST client that calls ES until it starts responding - but that wouldn't be self-contained.
sleep 120
docker stop service || true
docker-compose start service
The script itself runs to completion fine, but then "service" exits before it should.
Thanks!