'using enterypoint on docker file breakes the laravel build

hi i have a docker file like below :

. 
.
.
RUN composer config --global process-timeout 2000

# Copy source and create needed files & directories
COPY . /var/www/html


# Copy existing application directory permissions
RUN chmod -R  777 /var/www/html/storage/
RUN apt-get install -y htop
RUN apt-get install -y vim
RUN mv .env.staging .env


COPY ./docker/scripts/start.sh /usr/local/bin/start
RUN chown -R www-data:www-data /var/www/html \
    && chmod u+x /usr/local/bin/start



ENTRYPOINT sh "./docker/scripts/mainapp.entrypoint.sh"

and my mainapp.enterypoint.sh is like below :

#!/usr/bin/env sh
set -xe
chmod 777 -R storage
composer install
composer du
echo -e "Key generating...\n"
php artisan key:generate

#supervisord
service supervisor start


when it enters the entry point laravel container breakes with no error . but when i comment the line :

#ENTRYPOINT sh "./docker/scripts/mainapp.entrypoint.sh"

every thing builds up well . the only log i get from my container is this line :

+ echo -e Key generating...\n
+ php artisan key:generate
Application key set successfully.
+ service supervisor start
Starting supervisor: supervisord.

and no error and the container exists with error code :0

app exited with code 0


Solution 1:[1]

Broadly speaking, commands like service don't work in Docker. In your particular case, the service command may or may not run successfully, but it immediately returns; then you reach the end of the entrypoint script, and when you reach the end of the entrypoint script, the container aways exits.

Typically you'll want the entrypoint script to end with the special shell command exec "$@", which will switch over to running the main container command:

#!/bin/sh

# The application should have already been installed in the Dockerfile;
# no need to repeat it.

# Create key material if necessary.
if ! grep -q APP_KEY .env 2>/dev/null ; then
  php artisan key:generate
fi

# Run the main container command
exec "$@"

In your Dockerfile, set this script as the ENTRYPOINT (it must use JSON-array form), and set the single command you're going to run as the main container process as the CMD. This must run as a foreground process. It's usually better practice to run multiple separate containers than to try to run supervisord in a single container.

# Copy source and create needed files & directories
COPY . /var/www/html

# Install library dependencies
RUN composer install

# Metadata to run the container
ENTRYPOINT ["./docker/scripts/mainapp.entrypoint.sh"]
CMD ["php-fpm"]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Maze