I've created this image ( link ) that sets up an environment for an application social networking website.
This application needs a link with a Mysql container.
In the Dockerfile of my image ( link ) exists a RUN command with a shell script that installs and configures the application, as follows:
COPY . /elgg-docker/
RUN chmod +x /elgg-docker/elgg-install.sh
RUN /elgg-docker/elgg-install.sh
In this shell script contains a snippet of code waiting for the mysql server to respond to continue the application's installation:
#wait for mysql
i=0
while ! netcat $ELGG_DB_HOST $MYSQL_PORT >/dev/null 2>&1 < /dev/null; do
i='expr $i + 1'
if [ $i -ge $MYSQL_LOOPS ]; then
echo "$(date) - ${ELGG_DB_HOST}:${MYSQL_PORT} still not reachable, giving up."
exit 0
fi
echo "$(date) - waiting for ${ELGG_DB_HOST}:${MYSQL_PORT}... $i/$MYSQL_LOOPS."
sleep 1
done
My problem is that when I compile the image with the command "docker build -t keviocastro / elgg-docker." The installation shell script runs, and in the snippet that checks if the mysql server is available returns error and then the build of the image is not completed.
How can I identify, in the shell script or some other solution, that the command that is running is Docker build and porting the waiting snippet the mysql server does not need to be executed?