Using Docker version 20.10.18, build b40c2f6 on Ubuntu 20.04. This is how I am building the image and starting up the container.
#!/usr/bin/env bash # encoding:utf-8 IMAGE=tensorflow_serve CONTAINER=topic_classification docker image build --tag=$IMAGE ./ set -e # From this point onwards, any failure must exit the script HOST_PORT=80 CONTAINER_PORT=8080 docker container created --hostname $CONTAINER --publish $HOST_PORT:$CONTAINER_PORT --name $CONTAINER $IMAGE docker container start $CONTAINER # Exits immediately sleep 40s # Will explain
Now, starting the container takes some non-negligible time (about 30 seconds, to start up some internal service and mount some directories etc.) But I have noticed the start command exits even before the start up (inside the container) is complete.
Normally, this would not be a problem, but the point is, after starting up, my script moves on to run some integration tests assuming the container services are up (in reality, which are still booting up). I went around the problem by introducing the sleep command, but that does not look nice. It leaves me to estimate the start time, and add a good amount of buffer before I proceed to run the tests.
Is there any option to the start command that will block it until the container has started up all its services inside it? Or, am I approaching the whole problem in the wrong way, and should I use some very different commands instead?