T
T
Templar3d2022-01-11 18:39:33
PHP
Templar3d, 2022-01-11 18:39:33

How to run another command in docker?

I have a Dockerfile that starts with FROM php:7.4-fpm
and ends with CMD ["php-fpm"]
I need to additionally run the following command in it:

php /var/www/html/artisan queue:listen --memory=1024 --timeout=1800

I tried

CMD php-fpm && /usr/local/bin/php /var/www/html/artisan queue:listen --memory=1024 --timeout=1800

but since php-fpm is already running, no other command is executed.
Also tried

CMD php-fpm ; /usr/local/bin/php /var/www/html/artisan queue:listen --memory=1024 --timeout=1800

- doesn't work either.

How to run in docker so that both commands are executed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shurshur, 2022-01-11
@Templar3d

This is not considered a docker-way (it’s more correct to run a separate queue handler in a separate container), but you can do this:
one command & another command
. You can also make a script that starts everything as it should, and use it as a cmd. You can also inject a micro service management system like runit into the container.
Why is it considered wrong to do so? If php-fpm crashes, then the whole container will crash and may restart automatically. And if the second service falls, the container will work as if nothing had happened.

A
Andrew, 2022-01-11
@R0dger

Install Supervisor inside the container and describe your commands in it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question