T
T
timureh2017-08-18 10:59:49
Doctrine ORM
timureh, 2017-08-18 10:59:49

Docker container stops after launch?

There is a container with a mysql server database and a container with a web server.
If, after launch, you fill the database manually (go into the container and give a command), then everything works.
And if the database filling command is added to the Dockerfile of the container with the web server, then it stops after the command is executed (be it CMD or ENTRYPOINT). If you add restart: always to docker-compose.yml, then the container goes into an endless reboot. The Dockerfile looks like this:
FROM php:7.0-apache
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y git zlib1g-dev libicu-dev mc mysql-client \
&& docker-php-ext-install zip pdo_mysql intl \
&& a2enmod rewrite\
&& sed -i 's!/var/www/html!/var/www/public!g' /etc/apache2/sites-available/000-default.conf \
&& mv /var/www/html /var/www /public \
&& curl -sS https://getcomposer.org/installer \
| php -- --install-dir=/usr/local/bin --filename=composer
WORKDIR /var/www
ENTRYPOINT ["./vendor/bin/doctrine-module", "migrations:migrate"
] RUN, then, apparently, the files with the project have not yet been mounted, since the build falls into the error: /bin/sh: 1: ./vendor/bin/doctrine-module: not found
How to execute the command so that the container does not "fall"?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
RidgeA, 2017-08-18
@timureh

It doesn't crash - it works as it should: it stops after the command is executed.
If you then need to run a web server in it, then you can do something like this

CMD ./vendor/bin/doctrine-module migrations:migrate && <some_command_to_start_server>

N
Nicholas, 2017-08-18
@healqq

Make a separate container with the same image to perform migrations, write this command to it in docker-compose. Then, at startup, the container with migrations will rise, make migrations and die, and the main container with the service will continue to spin.

T
timureh, 2017-08-18
@timureh

RidgeA You are right! Thank you.
The final line looks like this:
First, you have to ping the container with the base for about 40 seconds, because it is being initialized.
I read what can be done with scripts like wait-for-it.sh, but in fact this is the same ping.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question