Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockerfile CMD not running at container start

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

like image 609
James Kirkby Avatar asked Feb 08 '16 13:02

James Kirkby


1 Answers

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 
like image 94
Sobrique Avatar answered Oct 13 '22 00:10

Sobrique