Reputation: 1131
I'm relatively new to Docker - I'm trying to build a system to run a Symfony 4 app, comprising of PHP-FPM, nginx and MySQL.
Everything works as it should except one thing. When the PHP-FPM container boots, I want to run:
#!/bin/bash
composer install
bin/console doctrine:database:create --if-not-exists
bin/console doctrine:schema:update --force
bin/console doctrine:fixtures:load --no-interaction
I created a script with these commands in and then edited my DockerFile as follows:
COPY ./docker/php/startup.sh /usr/local/bin/startup.sh
RUN ["chmod", "+x", "/usr/local/bin/startup.sh"]
ENTRYPOINT ["/usr/local/bin/startup.sh"]
The issue I'm having is that when I run docker-compose build
and then docker-compose up
, I can see the script runs, but something in it causes the container to fail and restart itself - the script then runs again, and the cycle continues. The docker-compose.yml has restart: unless-stopped
specified by the way.
I wondered if one of the commands was exiting with a non zero code, so tried to add exit 0
to the end of the script, but to no avail.
Am I doing something daft? To be clear, I want this script to run automatically on the first boot of the container (it's fine if it runs every boot for what it's worth, not just the very first time).
Upvotes: 2
Views: 1691
Reputation: 472
https://docs.docker.com/engine/reference/builder/#entrypoint
When you define entrypoint to your script. It runs it and after that it ends that means entrypoint is done.(so script executes no errors )
So you need to specify your entrypoint to php-fpm or even sleep will fix this.
Upvotes: 1