我正在学习docker,并试图为Symfony项目设置环境。在我将迁移和夹具创建命令添加到entrypoint.sh之前,它工作良好。现在,运行entrypoint.sh中的所有命令后,php容器将以代码0退出。有人可以帮我吗?
这是我的设置:
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}
用于php容器的Dockerfile:
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
答案 0 :(得分:0)
第一件事,容器将在执行入口点脚本时死亡,因为没有任何使容器在入口点运行的过程。应该始终有一个进程能够保持运行,以使容器不会死亡。
第二件事,您没有在入口点中启动php-fpm
,因此您的容器将不会在容器中启动PHP。
更新您的入口点。
#!/bin/sh
APP_PATH="/var/www/symfony"
echo "all params $@"
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
echo "starting php-fpm"
exec $@
更新Dockerfile中的CMD
CMD ["/usr/local/bin/entrypoint.sh","php-fpm","-F"]