16

So i've written a Dockerfile for a project, i've defined a CMD to run on starting the container to bootstrap the application.

The Dockerfile looks like

# create our mount folders and volumes
ENV MOUNTED_VOLUME_DIR=sites
RUN mkdir /$MOUNTED_VOLUME_DIR
ENV PATH=$MOUNTED_VOLUME_DIR/sbin:$MOUNTED_VOLUME_DIR/common/bin:$PATH
RUN chown -Rf www-data:www-data /$MOUNTED_VOLUME_DIR

# Mount folders
VOLUME ["/$MOUNTED_VOLUME_DIR/"]

# Expose Ports
EXPOSE 443

# add our environment variables to the server
ADD ./env /env

# Add entry point script
ADD ./start.sh /usr/bin/startContainer
RUN chmod 755 /usr/bin/startContainer

# define entrypoint command
CMD ["/bin/bash", "/usr/bin/startContainer"]

The start.sh script, does some git stuff like cloning the right repo, setting environment vars, as well as starting supervisor.

The start script begins with this

#!/bin/bash

now=$(date +"%T")
echo "Container Start Time : $now" >> /tmp/start.txt
/usr/bin/supervisord -n -c /etc/supervisord.conf

I start my new container like this

docker run -d -p expoPort:contPort -t -i -v /$MOUNTED_VOLUME_DIR/$PROJECT:/$MOUNTED_VOLUME_DIR $CONTAINER_ID /bin/bash

when i login to the container i see that supervisor hasn't been started, and neither has nginx or php5-fpm. the /tmp/start.txt file with a timestamp set from the startContainer script doesn't exist, showing its never ran the CMD in the Dockerfile.

Any hints on to get this fixed would be great

James Kirkby
  • 1,716
  • 5
  • 24
  • 46
  • 4
    you are replacing the CMD with your `/bin/bash` in your `docker run`so it is "normal" that your start script has not run – user2915097 Feb 08 '16 at 14:17

1 Answers1

30

This:

docker run -d -p expoPort:contPort -t -i -v /$MOUNTED_VOLUME_DIR/$PROJECT:/$MOUNTED_VOLUME_DIR $CONTAINER_ID /bin/bash

Says 'run /bin/bash' after instantiating the container. E.g. skip CMD.

Try this:

docker run -d -p expoPort:contPort -t -i -v /$MOUNTED_VOLUME_DIR/$PROJECT:/$MOUNTED_VOLUME_DIR $CONTAINER_ID 
Sobrique
  • 52,974
  • 7
  • 60
  • 101
  • Thanks that is right, thought you still had to pass bash into the start container – James Kirkby Feb 09 '16 at 13:31
  • It's a convenient way to override the default. Start with `bash`, run scripts, check config, etc. before running as a daemon with a startup script. – Sobrique Feb 09 '16 at 13:37