0

So Im building a Laravel application, I have a mysql db defined in my docker-compose.yml and an nginx webserver to go together with my php app.

this is the Dockerfile of the PHP app:

# Install dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    libpng-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev \
    locales \
    zip \
    jpegoptim optipng pngquant gifsicle \
    unzip \
    git \
    libonig-dev \
    libzip-dev \
    curl

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install extensions
RUN docker-php-ext-install pdo_mysql zip exif pcntl gd mysqli pdo

WORKDIR /var/www

COPY composer.lock composer.json ./

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=comp>

# Copy existing application directory contents
COPY . ./

RUN chown -R www-data:www-data /var/www

#laravel + packages install
RUN composer install

RUN chmod -R guo+w storage

# Expose port 9000 and start php-fpm server
EXPOSE 9000

CMD ["php-fpm"]

ENTRYPOINT ["/var/www/migrate.sh"]

the shell script just is this:

#!/bin/sh

nohup php artisan migrate:fresh --force

golb_app_1 exited with code 0
app_1        | Dropped all tables successfully.
app_1        | Migration table created successfully.
app_1        | Migrating: 2014_10_12_000000_create_users_table
app_1        | Migrated:  2014_10_12_000000_create_users_table (24.82ms)
app_1        | Migrating: 2014_10_12_100000_create_password_resets_table
app_1        | Migrated:  2014_10_12_100000_create_password_resets_table (17.29ms)
app_1        | Migrating: 2019_08_19_000000_create_failed_jobs_table
app_1        | Migrated:  2019_08_19_000000_create_failed_jobs_table (22.36ms)
app_1        | Migrating: 2021_06_09_080445_create_posts_table
app_1        | Migrated:  2021_06_09_080445_create_posts_table (47.77ms)
app_1        | Migrating: 2021_06_09_120221_update_users_table
app_1        | Migrated:  2021_06_09_120221_update_users_table (21.67ms)
golb_app_1 exited with code 0

Is the output that I am getting If i run my docker-compose up. Then Container will restart and do it again and again.

If I comment out the script and run it with docker exec It will run and the DB works fine.

ceejay
  • 23
  • 5

2 Answers2

1

"exited with code 0" means it run successfully. And since it's the entrypoint, its expected for the container to stop.

You need to run the serve command after migrate:

php artisan serve --host=0.0.0.0 --port=$APP_PORT

(see https://stackoverflow.com/a/48854030/1123052)

Edgar Domingues
  • 930
  • 1
  • 8
  • 17
  • `#!/bin/sh nohup php artisan migrate:fresh --seed &` gives me: golb_app_1 exited with code 0 golb_app_1 exited with code 0 golb_app_1 exited with code 0 golb_app_1 exited with code 0 golb_app_1 exited with code 0 golb_app_1 exited with code 0 golb_app_1 exited with code 0 golb_app_1 exited with code 0 ins my console – ceejay Aug 06 '21 at 07:26
  • Its not even the migrate command, if I just run the script with `echo "lol" &` I still only get exit code 0 – ceejay Aug 06 '21 at 07:36
  • The last command in the entrypoint script should be the one that runs the php server – Edgar Domingues Aug 06 '21 at 07:38
  • Edited the answer, based on https://stackoverflow.com/a/48854030/1123052 – Edgar Domingues Aug 06 '21 at 07:45
  • Wait, I did something wrong: I noticed that Im not using php artisan serve, Im using php-fpm I cut the code while pasting it or something. now I get bad gateway again... – ceejay Aug 06 '21 at 08:08
0
#!/bin/sh
sleep 15

php artisan migrate:fresh --force &

php-fpm

call script where php-fpm is called now (CMD) delete Entrypoint

ceejay
  • 23
  • 5