How to identify in a shell script, which is the docker command that is running

4

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?

    
asked by anonymous 10.12.2015 / 20:01

1 answer

1

You have to put your script either in the command CMD or in ENTRYPOINT of your Dockefile.

The command RUN will always execute the commands during the build of the image and "commit" a new layer of that image.

See more information in the Dockerfile documentation:

link

    
03.03.2016 / 05:28