docker build stops at RUN composer install with exit code 1
failed to solve: process "/bin/sh -c composer install" did not complete successfully: exit code: 1Short answer
Exit code 1 only says the RUN step failed. The real reason is a few lines above it in the build log. In a PHP image it is usually one of four things: Composer ran out of memory, unzip is missing, a PHP extension the project requires is not installed, or a composer script failed.
Fix it fast
1Find out which cause you have
Rebuild with plain progress output so the full Composer message stays on screen.
docker build --progress=plain --no-cache . 2>&1 | tail -n 602Match what you see, then jump to its fix
- 1
Allowed memory size of XXXXXX bytes exhaustedComposer runs out of PHP memoryFix - 2
The log shows packages that fail to unpack, and unzip is not found in the imageThe image has no unzip or 7zFix - 3
The log names a missing ext-* requirement, or the platform check stops the appA required PHP extension is not installed in the imageFix - 4
The failing line starts with the name of a script, such as post-autoload-dump, not with a downloadA composer script fails during the buildFix
- 1
What does the error look like?
failed to solve: process "/bin/sh -c composer install" did not complete successfully: exit code: 1Allowed memory size of ... bytes exhausted
Cause 1 of 4
Composer runs out of PHP memory
1Check
Read the memory limit PHP gives Composer inside the image.
docker run --rm your-image php -r 'echo ini_get("memory_limit"), PHP_EOL;'2Fix
Use Composer 2, and raise the limit for the install step with the COMPOSER_MEMORY_LIMIT environment variable.
RUN COMPOSER_MEMORY_LIMIT=-1 composer install --no-interaction3Verify
The install step completes.
docker build --progress=plain .Confirmed by getcomposer.org
Cause 2 of 4
The image has no unzip or 7z
1Check
Composer unpacks archives with the system unzip or 7z, or PHP's ZipArchive. Slim images ship none of the tools, and Alpine-based images leave out others.
docker run --rm your-image sh -c 'which unzip 7z; php -m | grep -i zip'2Fix
Install unzip with the image's package manager before running Composer.
RUN apt-get update && apt-get install -y --no-install-recommends unzip git \
&& rm -rf /var/lib/apt/lists/*3Verify
Rebuild and watch the install extract packages normally.
docker build --progress=plain .Confirmed by getcomposer.org
Cause 3 of 4
A required PHP extension is not installed in the image
1Check
Compare the extensions the project needs with what the image has. The official PHP image lists its built-ins with php -m, and extra ones are added with its own scripts.
docker run --rm your-image php -m
composer check-platform-reqs2Fix
Install the extension in the Dockerfile before composer install. Do not hide the problem with --ignore-platform-req unless the extension is truly not needed at runtime.
RUN apt-get update && apt-get install -y libfreetype-dev libjpeg62-turbo-dev libpng-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd3Verify
composer check-platform-reqs returns zero.
docker run --rm your-image composer check-platform-reqsConfirmed by hub.docker.com
Cause 4 of 4
A composer script fails during the build
1Check
Scripts in composer.json run after install and may need app code, an .env file or services that are not in the image yet.
grep -n -A6 '"scripts"' composer.json2Fix
Install without scripts first, copy the application, then run the scripts in a later step.
COPY composer.json composer.lock ./
RUN composer install --no-scripts --no-autoloader --no-interaction
COPY . .
RUN composer dump-autoload --optimize3Verify
Both steps pass.
docker build --progress=plain .Confirmed by getcomposer.org
How do I stop it coming back?
- Commit composer.lock and install from it, so builds do not change between runs.
- Run composer check-platform-reqs as a build step.
- Keep composer install before the COPY of your source so Docker can cache it.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- Spotless LaundryAn on-demand laundry app: Flutter on a Laravel back end, with Firebase for live updates.
Related fixes
Back end
composer require laravel/horizon fails: ext-pcntl is missing
laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system
Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.
3 causes, each with a fixBack end
memory_limit does not change inside a PHP Docker container
memory_limit is still 128M after editing php.ini in the container
Your setting is being read from the wrong place or overridden.
4 causes, each with a fixBack end
php artisan serve starts but the app is not reachable, or the .env is ignored
Server stops right after start with a non-zero exit code when --port is given and the port is busy
php artisan serve listens on 127.0.0.1 port 8000 by default.
4 causes, each with a fixBack end
Guzzle or Http::get fails with cURL error 6 in Laravel
Illuminate\Http\Client\ConnectionException: cURL error 6: Could not resolve host
cURL error 6 means the machine running PHP could not turn the host name in the URL into an IP address.
3 causes, each with a fixBack end
Laravel cannot find the database host: getaddrinfo failed
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed
The message means PHP could not turn DB_HOST into an IP address.
3 causes, each with a fixBack end
mysqli is missing in a PHP Docker container
php -m does not list mysqli
The official php image ships a small set of extensions, so mysqli is often absent.
3 causes, each with a fix