I'm learning docker and was trying to set up the environment for a Symfony project. It works well until I added the migration and fixtures creation commands to entrypoint.sh. Now the php container will exit with code 0 after running all the commands in entrypoint.sh. Can someone help me with this?
Here is my setup:
docker-compose.yaml
version: "3.7"
services:
nginx:
image: nginx:alpine
ports:
- ${NGINX_HOST_PORT}:80
volumes:
- ./public:/var/www/symfony/public
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
php:
build:
context: .
dockerfile: docker/php/Dockerfile
volumes:
- symfony:/var/www/symfony:delegated
depends_on:
- mysql
- redis
- composer
environment:
REDIS_HOST: redis
REDIS_PORT: 6379
redis:
image: redis:alpine
composer:
image: composer:latest
command: install
volumes:
- symfony:/app
mysql:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
ports:
- ${MYSQL_HOST_PORT}:3306
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
volumes:
symfony:
# driver: local
# driver_opts:
# type: none
# o: bind
# device: ${PWD}:${PWD}
driver: local
driver_opts:
type: nfs
o: addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3
device: ${PWD}:${PWD}
Dockerfile for php container:
FROM php:7.3-fpm-alpine
ENV APP_DEPENDENCIES \
curl \
vim \
git
ENV PHP_EXTENSIONS \
pdo_mysql
ENV PECL_EXTENSIONS \
xdebug \
redis
RUN apk add --no-cache ${APP_DEPENDENCIES} ${PHPIZE_DEPS} && \
docker-php-ext-install ${PHP_EXTENSIONS} && \
pecl install ${PECL_EXTENSIONS} && \
docker-php-ext-enable ${PECL_EXTENSIONS}
COPY ./ /var/www/symfony
COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
CMD ["/usr/local/bin/entrypoint.sh"]
entrypoint.sh:
#!/bin/sh
APP_PATH="/var/www/symfony"
echo "applying db migrations"
${APP_PATH}/bin/console doctrine:migrations:migrate first
${APP_PATH}/bin/console doctrine:migrations:migrate
${APP_PATH}/bin/console doctrine:fixtures:load