I'm trying to write a script that:
- Runs
docker-compose up -dto orchestrate some services (database, etc.) - Runs
eb local runto start the web container. - Connects the web container to the docker network created by docker-compose
The issue I'm having is with eb local run because it seems to be blocking, yet won't work as a background process. Here's a sample of my script:
docker-compose up -d # Run backing services, postgres, redis, amqp, etc.
eb local run > ./logs/eb.log 2>&1 & # Run web container with eb
# Wait for container to be running
spin="-\|/"
i=0
until [ "$(docker ps -q --filter expose=8080)" ]; do
i=$(( (i+1) %4 ))
printf "\r${spin:$i:1}"
done
### This section connects the elasticbeanstalk container to the network configured by docker compose
EB_DOCKER_CONTAINER_ID=$(docker ps -q --filter expose=8080)
DEFAULT_DOCKER_NETWORK_NAME="${${PWD##*/}//[\-\_]/}_default"
docker network connect ${DEFAULT_DOCKER_NETWORK_NAME} ${EB_DOCKER_CONTAINER_ID}
When I run this it prints [2] + 82322 suspended (tty output) eb local run > ./logs/eb.log 2>&1 and is stuck in the loop waiting for the web container to start.
I've also tried some variations such as:
nohup eb local run &
Results in [2] + 82322 suspended (tty output) ( eb local run; ). The nohup.out file shows that docker got up to building the image, but does not execute uwsgi.
Also if I run the fg command I get the message:
unable to setup input stream: unable to set IO streams as raw terminal: interrupted system call
ERROR: None
If instead I run nohup eb local run the container is run but the script doesn't progress past the nohup eb local run command. The nohup.out file shows that uwsgi was started *** Starting uWSGI 2.0.15 (64bit) on [Fri Oct 6 04:47:47 2017] ***, however the web container is not connected to the docker network.
If I run ps | grep docker after the script has run, I do in-fact see the underlying docker run command. i.e.
docker run -i -t --rm -p 8080:8080 --env KEY=VALUE -v /Users/me/Projects/my_api/.elasticbeanstalk/logs/local/171006_160403886032:/var/app/logs --name a81919b7750b87c5d6b0c85ad6088baef308d5de 06c07d928cea
I invoke the script as . ./bin/start.sh, does anyone know how I could run eb local run from a script in this way, or any appropriate pointers/tips would be appreciated.