【发布时间】:2021-08-06 19:26:39
【问题描述】:
所以我正在构建一个 Laravel 应用程序,我在 docker-compose.yml 中定义了一个 mysql 数据库和一个 nginx 网络服务器来与我的 php 应用程序一起使用。
这是 PHP 应用程序的 Dockerfile:
# 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"]
shell 脚本是这样的:
#!/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
如果我运行我的 docker-compose up,我得到的输出是什么。 然后 Container 将重新启动并一次又一次地这样做。
如果我注释掉脚本并使用 docker exec 运行它,它将运行并且数据库工作正常。
【问题讨论】: