Docker Community Forums

Share and learn in the Docker community.

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


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.


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

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

FROM java:8

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