In my Laravel project I upgraded to currently latest Laravel 9.3.0 and PHP 8.0.16.
The original version was Laravel 8.64 with PHP 7.4.
I run the project in Docker containers with php:8.0.16-fpm-alpine
image. Previous was php:7.4-fpm-alpine
.
This is my Docker container config in docker-compose.yml
file:
version: "3"
services:
php:
build:
context: ./.docker-config/dockerfiles
dockerfile: php.dockerfile
volumes:
- ./laravel:/var/www/html:delegated
networks:
- mynetwork
And here is the php.dockerfile
:
FROM php:8.0.16-fpm-alpine
WORKDIR /var/www/html
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ --allow-untrusted gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
ENV PHP_MEMORY_LIMIT=2G
ENV PHP_UPLOAD_MAX_FILESIZE: 512M
ENV PHP_POST_MAX_SIZE: 512M
RUN docker-php-ext-install pdo pdo_mysql
# ...
As you see I set 2 GB for PHP memory limit.
When I run docker-compose run --rm phpunit
I get this error:
PHPUnit 9.5.16 by Sebastian Bergmann and contributors.
............................................................... 63 / 281 ( 22%)
......................
Symfony\Component\ErrorHandler\Error\FatalError
Allowed memory size of 134217728 bytes exhausted (tried to allocate 5242880 bytes)
at database/migrations/2022_01_21_120600_create_tags_table.php:16
12▕ * @return void
13▕ */
14▕ public function up()
15▕ {
➜ 16▕ Schema::create('tags', function (Blueprint $table) {
17▕ $table->id();
18▕ $table->string('name')->default('');
19▕ $table->string('type')->default('');
20▕ $table->string('color', 7)->default('');
Here is the referred migration file. I think, nothing special:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('tags', function (Blueprint $table) {
$table->id();
$table->string('name')->default('');
$table->string('type')->default('');
$table->string('color', 7)->default('');
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('tags');
}
};
Earlier same error happend on different migration file.
Any idea what's going on and how can I solve this issue?
Thanks!
CodePudding user response:
You can use in Dockerfile for solving memory limitation
RUN echo memory_limit = -1 >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini;