Skip to content
Advertisement

How to run cron and web application in same container?

I am new to docker. Hardly I have containerized my php application to run it in the web interface. But I have some cron to run with it. I learnt how to create separate cron image and run it from How to run a cron job inside a docker container?. But my use case is different. I need to use the php files from my php application container which seems not possible from my way. I tried creating the docker-compose.yml as follow to see if it would work

docker-compose.yml:

JavaScript

As I have commented entry point here and if I do docker-compose up, everything works perfectly fine, My Dockerfile is as under

Dockerfile:

JavaScript

My cron.sh file is as under

JavaScript

But with the entry point commented, i cannot run cron. If i don’t comment entrypoint, then cron runs, my web application doesn’t. Is there any possibility to fix this?

Thanks

Advertisement

Answer

At the end of the docker file i added the following code after removing

RUN a2enmod rewrite headers

JavaScript

and cron.sh was changed to

JavaScript

This worked for me. I need not have to add entry neither on docker-compose nor on docker file, but I guess entry also would work. I don’t know if this is the right way to do. If anyone would give me more advance idea, I would be happy to give it a try. Thanks

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement