container start run a script

3.6k Views Asked by At

I want to have a script that runs in my docker container at every start/restart. It should run the bash of the container with:

cd app
Console/cake schema update

and

Console/cake migration

I tired to run a process or write something in my dockerfile, but that all doesnt work for me. I also read the "Run multiple services in a container" from docker, but i didnt find a solution.

COPY starter.sh /etc/init.d/starter.sh

RUN chmod +x /etc/init.d/starter.sh
RUN chmod 755 /etc/init.d/starter.sh
RUN update-rc.d starter defaults 10
RUN /etc/init.d/starter.sh

in my starter.sh is some test code like

RUN mkdir /var/www/hello

that i know if it works

1

There are 1 best solutions below

10
mchawre On

Make use of ENTRYPOINT in dockerfile

Add these lines in dockerfile

COPY starter.sh /opt/starter.sh
ENTRYPOINT ["/opt/starter.sh"]

Update:

If you want to run apache web server then add these lines

ENTRYPOINT ["/path/to/apache2"]
CMD ["-D", "FOREGROUND"]

This will run apache2 as first process inside container in daemon mode.