Docker Community Forums

Share and learn in the Docker community.

Auto database update (Auto execute of an command after container start)?

Hello,

i’m quite new to docker so i try to learn.
Today i try to dockerize my PHP application.

So i want to build an image which contains nginx + php (fpm).
I guess this should not be the problem, my main problem is how i can update automatically the database if i update the application.

Want i want is to execute the migration command of symfony (php framework) always on startup, so the database is always up2date.

Is that possible without a docker-compose file with the command option ?
Maybe i know to less about docker, but it seems its not that user friendly if a user has to create a docker-compose file with that option for one image.

Thanks!

Not sure this will solves your problem, but its worth check my repo’sDockerfile

I have created a simple run.sh file copied to docker image and in the Dockerfile I wrote CMD [“run.sh”]. In the same way define whatever you want in run.sh and write CMD [“run.sh”]. You can find another example like below

Dockerfile
FROM java:8

RUN apt-get update && apt-get install stress-ng -y
ADD target/restapp.jar /restapp.jar
COPY dockerrun.sh /usr/local/bin/dockerrun.sh
RUN chmod +x /usr/local/bin/dockerrun.sh
CMD [“dockerrun.sh”]
dockerrun.sh
#!/bin/sh
java -Dserver.port=8095 -jar /restapp.jar &
hostname="hostname: hostname"
nohup stress-ng --vm 4 &
while true; do
sleep 1000
done

Admin
Apps4Rent