Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in AWS by (19.1k points)

I'm deploying Docker containers (detached) to an AWS EC2 registry using CodeDeploy. On deploy, the following command is run after setting some environmental variables etc:

exec docker run -d ${PORTS} -v cache-${CACHE_VOLUME} --env-file $(dirname $0)/docker.env --tty "${IMAGE}:${TAG}"

The container runs an image located and tagged in EC2 Container Service. No problems so far.

Since this is a PHP application (specifically a Symfony2 application) I would normally need to issue the following command to execute database migrations on deployment:

 php app/console doctrine:migrations:migrate --no-interaction

Now, is there any to run this command during "docker run..." while keeping the container running, or do I need to run another container specifically for this command?

1 Answer

0 votes
by (44.4k points)

An entrypoint has to be created which runs at the startup of the container.

entrypoint.sh file:

#create or update db

./waitforit.sh <DB_HOST>:<DP_PORT> -t 30

php app/console doctrine:migrations:execute 

# start apache

Apache2-foreground

This is the link for the GitHub repo which has the script which is waited when the database is started up.

Related questions

0 votes
1 answer
asked Oct 10, 2019 in AWS by yuvraj (19.1k points)
Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...