1

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

2
  • what script do you want to run? did you try with entrypoint or CMD command?
    – golobitch
    Jul 18, 2019 at 10:47
  • yes but it didnt work for me because my container stopped after the script
    – andre.hey
    Jul 18, 2019 at 10:49

1 Answer 1

1

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.

10
  • but how can i run bash in my script? And if i do it like you said it runs the script and end the process of apache. the container is stopped
    – andre.hey
    Jul 18, 2019 at 10:49
  • 1
    provide contents of starter.sh then only I can answer it.
    – mchawre
    Jul 18, 2019 at 10:50
  • if your container stopped after the script then the problem is probably in the script. Can you provide content of this script? You can also try to execute commands from your script in container to see which command is problematic
    – golobitch
    Jul 18, 2019 at 10:51
  • i run only mkdir. Can i start the apache process after it? with apache2 -D FOREGROUND
    – andre.hey
    Jul 18, 2019 at 10:53
  • the update code in the starter.sh or in the dockerfile after the script runs?
    – andre.hey
    Jul 18, 2019 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.