'Dockerize existing Laravel 8 project with dependencies - how to run composer update inside docker?
I have install Docker on a clean install of Monterey. I can create a new Laravel 9 project. I also managed to install a container for mySQL and one for phpMyAdmin which I can access in the browser.
After updating the Dockerfile as advised (see below) when I try to dockerize an existing Laravel 8 project (after creating the Dockerfile and docker-compose.yml files as explained in this article) with extra depencies, I get the following errors:
$ docker-compose build
db uses an image, skipping
phpmyadmin uses an image, skipping
Building app
[+] Building 56.5s (8/11)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 649B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/php:8.0 5.0s
=> [1/7] FROM docker.io/library/php:8.0@sha256:28d552fb96c848fcaa8b9fba9fedcaccbfadf7a108dc896be7cbc78b11417673 13.5s
=> => resolve docker.io/library/php:8.0@sha256:28d552fb96c848fcaa8b9fba9fedcaccbfadf7a108dc896be7cbc78b11417673 0.0s
...
=> [internal] load build context 12.6s
=> => transferring context: 289.97MB 12.5s
=> [2/7] RUN apt-get update -y && apt-get install -y openssl zip unzip git 17.9s
=> [3/7] RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer 6.6s
=> ERROR [4/7] RUN docker-php-ext-install pdo pdo_mysql zip 13.5s
------
> [4/7] RUN docker-php-ext-install pdo pdo_mysql zip:
#7 1.864 Configuring for:
#7 1.864 PHP Api Version: 20200930
#7 1.864 Zend Module Api No: 20200930
#7 1.864 Zend Extension Api No: 420200930
#7 2.692 checking for grep that handles long lines and -e... /bin/grep
#7 2.694 checking for egrep... /bin/grep -E
#7 2.696 checking for a sed that does not truncate output... /bin/sed
#7 2.732 checking for pkg-config... /usr/bin/pkg-config
#7 2.732 checking pkg-config is at least version 0.9.0... yes
#7 2.743 checking for cc... cc
#7 2.774 checking whether the C compiler works... yes
#7 2.887 checking for C compiler default output file name... a.out
#7 2.889 checking for suffix of executables...
#7 2.928 checking whether we are cross compiling... no
#7 2.996 checking for suffix of object files... o
#7 3.018 checking whether we are using the GNU C compiler... yes
#7 3.042 checking whether cc accepts -g... yes
#7 3.065 checking for cc option to accept ISO C89... none needed
#7 3.112 checking how to run the C preprocessor... cc -E
#7 3.177 checking for icc... no
#7 3.188 checking for suncc... no
#7 3.199 checking for system library directory... lib
#7 3.199 checking if compiler supports -Wl,-rpath,... yes
#7 3.244 checking build system type... x86_64-pc-linux-gnu
#7 3.252 checking host system type... x86_64-pc-linux-gnu
#7 3.252 checking target system type... x86_64-pc-linux-gnu
#7 3.298 checking for PHP prefix... /usr/local
#7 3.298 checking for PHP includes... -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
#7 3.299 checking for PHP extension directory... /usr/local/lib/php/extensions/no-debug-non-zts-20200930
#7 3.300 checking for PHP installed headers prefix... /usr/local/include/php
#7 3.300 checking if debug is enabled... no
#7 3.330 checking if zts is enabled... no
#7 3.347 checking for gawk... no
#7 3.348 checking for nawk... nawk
#7 3.349 checking if nawk is broken... no
#7 3.352 checking whether to enable PDO support... yes, shared
#7 3.374 checking for a sed that does not truncate output... /bin/sed
#7 3.378 checking for ld used by cc... /usr/bin/ld
#7 3.384 checking if the linker (/usr/bin/ld) is GNU ld... yes
#7 3.387 checking for /usr/bin/ld option to reload object files... -r
#7 3.388 checking for BSD-compatible nm... /usr/bin/nm -B
#7 3.392 checking whether ln -s works... yes
#7 3.392 checking how to recognize dependent libraries... pass_all
#7 3.417 checking for ANSI C header files... yes
#7 3.533 checking for sys/types.h... yes
#7 3.566 checking for sys/stat.h... yes
#7 3.603 checking for stdlib.h... yes
#7 3.635 checking for string.h... yes
#7 3.671 checking for memory.h... yes
#7 3.714 checking for strings.h... yes
#7 3.747 checking for inttypes.h... yes
#7 3.787 checking for stdint.h... yes
#7 3.821 checking for unistd.h... yes
#7 3.861 checking dlfcn.h usability... yes
#7 3.892 checking dlfcn.h presence... yes
#7 3.904 checking for dlfcn.h... yes
#7 3.906 checking the maximum length of command line arguments... 1572864
#7 3.912 checking command to parse /usr/bin/nm -B output from cc object... ok
#7 3.984 checking for objdir... .libs
#7 3.988 checking for ar... ar
#7 3.989 checking for ranlib... ranlib
#7 3.990 checking for strip... strip
#7 4.046 checking if cc supports -fno-rtti -fno-exceptions... no
#7 4.073 checking for cc option to produce PIC... -fPIC
#7 4.074 checking if cc PIC flag -fPIC works... yes
#7 4.098 checking if cc static flag -static works... yes
#7 4.217 checking if cc supports -c -o file.o... yes
#7 4.251 checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
#7 4.268 checking whether -lc should be explicitly linked in... no
#7 4.297 checking dynamic linker characteristics... GNU/Linux ld.so
#7 4.315 checking how to hardcode library paths into programs... immediate
#7 4.315 checking whether stripping libraries is possible... yes
#7 4.320 checking if libtool supports shared libraries... yes
#7 4.320 checking whether to build shared libraries... yes
#7 4.320 checking whether to build static libraries... no
#7 4.505
#7 4.505 creating libtool
#7 4.528 appending configuration tag "CXX" to libtool
#7 4.609 configure: patching config.h.in
#7 4.612 configure: creating ./config.status
#7 4.676 config.status: creating config.h
#7 4.729 /bin/bash /usr/src/php/ext/pdo/libtool --mode=compile cc -I. -I/usr/src/php/ext/pdo -I/usr/src/php/ext/pdo/include -I/usr/src/php/ext/pdo/main -I/usr/src/php/ext/pdo -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -c /usr/src/php/ext/pdo/pdo.c -o pdo.lo
#7 4.833 mkdir .libs
...
#7 7.480 creating pdo.la
#7 7.489 (cd .libs && rm -f pdo.la && ln -s ../pdo.la pdo.la)
#7 7.492 /bin/bash /usr/src/php/ext/pdo/libtool --mode=install cp ./pdo.la /usr/src/php/ext/pdo/modules
#7 7.528 cp ./.libs/pdo.so /usr/src/php/ext/pdo/modules/pdo.so
#7 7.532 cp ./.libs/pdo.lai /usr/src/php/ext/pdo/modules/pdo.la
#7 7.553 PATH="$PATH:/sbin" ldconfig -n /usr/src/php/ext/pdo/modules
#7 7.556 ----------------------------------------------------------------------
#7 7.557 Libraries have been installed in:
#7 7.557 /usr/src/php/ext/pdo/modules
#7 7.557
#7 7.557 If you ever happen to want to link against installed libraries
#7 7.557 in a given directory, LIBDIR, you must either use libtool, and
#7 7.557 specify the full pathname of the library, or use the `-LLIBDIR'
#7 7.557 flag during linking and do at least one of the following:
#7 7.557 - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
#7 7.557 during execution
#7 7.557 - add LIBDIR to the `LD_RUN_PATH' environment variable
#7 7.557 during linking
#7 7.557 - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
#7 7.557 - have your system administrator add LIBDIR to `/etc/ld.so.conf'
#7 7.557
#7 7.557 See any operating system documentation about shared libraries for
#7 7.557 more information, such as the ld(1) and ld.so(8) manual pages.
#7 7.559 ----------------------------------------------------------------------
#7 7.561
#7 7.562 Build complete.
#7 7.564 Don't forget to run 'make test'.
#7 7.565
#7 7.569 + strip --strip-all modules/pdo.so
#7 7.598 Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20200930/
#7 7.741 Installing header files: /usr/local/include/php/
#7 7.836 Installing PDO headers: /usr/local/include/php/ext/pdo/
#7 8.006
#7 8.006 warning: pdo (pdo.so) is already loaded!
#7 8.006
#7 8.008 find . -name \*.gcno -o -name \*.gcda | xargs rm -f
#7 8.013 find . -name \*.lo -o -name \*.o | xargs rm -f
#7 8.018 find . -name \*.la -o -name \*.a | xargs rm -f
#7 8.022 find . -name \*.so | xargs rm -f
#7 8.027 find . -name .libs -a -type d|xargs rm -rf
#7 8.031 rm -f libphp.la modules/* libs/*
#7 8.033 rm -f ext/opcache/jit/zend_jit_x86.c
#7 8.064 Configuring for:
#7 8.064 PHP Api Version: 20200930
#7 8.064 Zend Module Api No: 20200930
#7 8.064 Zend Extension Api No: 420200930
#7 8.831 checking for grep that handles long lines and -e... /bin/grep
#7 8.834 checking for egrep... /bin/grep -E
#7 8.836 checking for a sed that does not truncate output... /bin/sed
#7 8.870 checking for pkg-config... /usr/bin/pkg-config
#7 8.870 checking pkg-config is at least version 0.9.0... yes
#7 8.873 checking for cc... cc
#7 8.904 checking whether the C compiler works... yes
#7 8.946 checking for C compiler default output file name... a.out
#7 8.947 checking for suffix of executables...
#7 8.988 checking whether we are cross compiling... no
#7 9.031 checking for suffix of object files... o
#7 9.053 checking whether we are using the GNU C compiler... yes
#7 9.075 checking whether cc accepts -g... yes
#7 9.097 checking for cc option to accept ISO C89... none needed
#7 9.130 checking how to run the C preprocessor... cc -E
#7 9.182 checking for icc... no
#7 9.193 checking for suncc... no
#7 9.204 checking for system library directory... lib
#7 9.204 checking if compiler supports -Wl,-rpath,... yes
#7 9.248 checking build system type... x86_64-pc-linux-gnu
#7 9.254 checking host system type... x86_64-pc-linux-gnu
#7 9.255 checking target system type... x86_64-pc-linux-gnu
#7 9.298 checking for PHP prefix... /usr/local
#7 9.299 checking for PHP includes... -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
#7 9.299 checking for PHP extension directory... /usr/local/lib/php/extensions/no-debug-non-zts-20200930
#7 9.299 checking for PHP installed headers prefix... /usr/local/include/php
#7 9.299 checking if debug is enabled... no
#7 9.316 checking if zts is enabled... no
#7 9.332 checking for gawk... no
#7 9.333 checking for nawk... nawk
#7 9.334 checking if nawk is broken... no
#7 9.336 checking for MySQL support for PDO... yes, shared
#7 9.336 checking for the location of libz... no
#7 9.338 checking for MySQL UNIX socket location...
#7 9.339 checking for PDO includes... /usr/local/include/php/ext
#7 9.348 checking for a sed that does not truncate output... /bin/sed
#7 9.352 checking for ld used by cc... /usr/bin/ld
#7 9.358 checking if the linker (/usr/bin/ld) is GNU ld... yes
#7 9.362 checking for /usr/bin/ld option to reload object files... -r
#7 9.362 checking for BSD-compatible nm... /usr/bin/nm -B
#7 9.365 checking whether ln -s works... yes
#7 9.365 checking how to recognize dependent libraries... pass_all
#7 9.383 checking for ANSI C header files... yes
#7 9.492 checking for sys/types.h... yes
#7 9.526 checking for sys/stat.h... yes
#7 9.558 checking for stdlib.h... yes
#7 9.590 checking for string.h... yes
#7 9.625 checking for memory.h... yes
#7 9.658 checking for strings.h... yes
#7 9.692 checking for inttypes.h... yes
#7 9.728 checking for stdint.h... yes
#7 9.762 checking for unistd.h... yes
#7 9.799 checking dlfcn.h usability... yes
#7 9.831 checking dlfcn.h presence... yes
#7 9.846 checking for dlfcn.h... yes
#7 9.848 checking the maximum length of command line arguments... 1572864
#7 9.855 checking command to parse /usr/bin/nm -B output from cc object... ok
#7 9.931 checking for objdir... .libs
#7 9.935 checking for ar... ar
#7 9.936 checking for ranlib... ranlib
#7 9.936 checking for strip... strip
#7 9.994 checking if cc supports -fno-rtti -fno-exceptions... no
#7 10.02 checking for cc option to produce PIC... -fPIC
#7 10.02 checking if cc PIC flag -fPIC works... yes
#7 10.04 checking if cc static flag -static works... yes
#7 10.12 checking if cc supports -c -o file.o... yes
#7 10.15 checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
#7 10.17 checking whether -lc should be explicitly linked in... no
#7 10.19 checking dynamic linker characteristics... GNU/Linux ld.so
#7 10.21 checking how to hardcode library paths into programs... immediate
#7 10.21 checking whether stripping libraries is possible... yes
#7 10.22 checking if libtool supports shared libraries... yes
#7 10.22 checking whether to build shared libraries... yes
#7 10.22 checking whether to build static libraries... no
#7 10.40
#7 10.40 creating libtool
#7 10.42 appending configuration tag "CXX" to libtool
#7 10.50 configure: patching config.h.in
#7 10.50 configure: creating ./config.status
#7 10.56 config.status: creating config.h
#7 10.61 /bin/bash /usr/src/php/ext/pdo_mysql/libtool --mode=compile cc -I. -I/usr/src/php/ext/pdo_mysql -I/usr/src/php/ext/pdo_mysql/include -I/usr/src/php/ext/pdo_mysql/main -I/usr/src/php/ext/pdo_mysql -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/include/php/ext -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -c /usr/src/php/ext/pdo_mysql/pdo_mysql.c -o pdo_mysql.lo
#7 10.72 mkdir .libs
...
#7 11.74 creating pdo_mysql.la
#7 11.75 (cd .libs && rm -f pdo_mysql.la && ln -s ../pdo_mysql.la pdo_mysql.la)
#7 11.76 /bin/bash /usr/src/php/ext/pdo_mysql/libtool --mode=install cp ./pdo_mysql.la /usr/src/php/ext/pdo_mysql/modules
#7 11.79 cp ./.libs/pdo_mysql.so /usr/src/php/ext/pdo_mysql/modules/pdo_mysql.so
#7 11.79 cp ./.libs/pdo_mysql.lai /usr/src/php/ext/pdo_mysql/modules/pdo_mysql.la
#7 11.82 PATH="$PATH:/sbin" ldconfig -n /usr/src/php/ext/pdo_mysql/modules
#7 11.82 ----------------------------------------------------------------------
#7 11.82 Libraries have been installed in:
#7 11.82 /usr/src/php/ext/pdo_mysql/modules
#7 11.82
#7 11.82 If you ever happen to want to link against installed libraries
#7 11.82 in a given directory, LIBDIR, you must either use libtool, and
#7 11.82 specify the full pathname of the library, or use the `-LLIBDIR'
#7 11.82 flag during linking and do at least one of the following:
#7 11.82 - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
#7 11.82 during execution
#7 11.82 - add LIBDIR to the `LD_RUN_PATH' environment variable
#7 11.82 during linking
#7 11.82 - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
#7 11.82 - have your system administrator add LIBDIR to `/etc/ld.so.conf'
#7 11.82
#7 11.82 See any operating system documentation about shared libraries for
#7 11.82 more information, such as the ld(1) and ld.so(8) manual pages.
#7 11.82 ----------------------------------------------------------------------
#7 11.82
#7 11.82 Build complete.
#7 11.83 Don't forget to run 'make test'.
#7 11.83
#7 11.83 + strip --strip-all modules/pdo_mysql.so
#7 11.86 Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20200930/
#7 11.93 find . -name \*.gcno -o -name \*.gcda | xargs rm -f
#7 11.93 find . -name \*.lo -o -name \*.o | xargs rm -f
#7 11.94 find . -name \*.la -o -name \*.a | xargs rm -f
#7 11.94 find . -name \*.so | xargs rm -f
#7 11.95 find . -name .libs -a -type d|xargs rm -rf
#7 11.95 rm -f libphp.la modules/* libs/*
#7 11.96 rm -f ext/opcache/jit/zend_jit_x86.c
#7 11.99 Configuring for:
#7 11.99 PHP Api Version: 20200930
#7 11.99 Zend Module Api No: 20200930
#7 11.99 Zend Extension Api No: 420200930
#7 12.78 checking for grep that handles long lines and -e... /bin/grep
#7 12.78 checking for egrep... /bin/grep -E
#7 12.78 checking for a sed that does not truncate output... /bin/sed
#7 12.81 checking for pkg-config... /usr/bin/pkg-config
#7 12.81 checking pkg-config is at least version 0.9.0... yes
#7 12.82 checking for cc... cc
#7 12.84 checking whether the C compiler works... yes
#7 12.88 checking for C compiler default output file name... a.out
#7 12.88 checking for suffix of executables...
#7 12.92 checking whether we are cross compiling... no
#7 12.96 checking for suffix of object files... o
#7 12.99 checking whether we are using the GNU C compiler... yes
#7 13.01 checking whether cc accepts -g... yes
#7 13.03 checking for cc option to accept ISO C89... none needed
#7 13.06 checking how to run the C preprocessor... cc -E
#7 13.12 checking for icc... no
#7 13.13 checking for suncc... no
#7 13.14 checking for system library directory... lib
#7 13.14 checking if compiler supports -Wl,-rpath,... yes
#7 13.18 checking build system type... x86_64-pc-linux-gnu
#7 13.19 checking host system type... x86_64-pc-linux-gnu
#7 13.19 checking target system type... x86_64-pc-linux-gnu
#7 13.23 checking for PHP prefix... /usr/local
#7 13.23 checking for PHP includes... -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
#7 13.23 checking for PHP extension directory... /usr/local/lib/php/extensions/no-debug-non-zts-20200930
#7 13.23 checking for PHP installed headers prefix... /usr/local/include/php
#7 13.23 checking if debug is enabled... no
#7 13.24 checking if zts is enabled... no
#7 13.26 checking for gawk... no
#7 13.26 checking for nawk... nawk
#7 13.26 checking if nawk is broken... no
#7 13.26 checking for zip archive read/write support... yes, shared
#7 13.27 checking for libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0... no
#7 13.28 configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:
#7 13.28
#7 13.28 No package 'libzip' found
#7 13.28 No package 'libzip' found
#7 13.28 No package 'libzip' found
#7 13.28
#7 13.28 Consider adjusting the PKG_CONFIG_PATH environment variable if you
#7 13.28 installed software in a non-standard prefix.
#7 13.28
#7 13.28 Alternatively, you may set the environment variables LIBZIP_CFLAGS
#7 13.28 and LIBZIP_LIBS to avoid the need to call pkg-config.
#7 13.28 See the pkg-config man page for more details.
------
executor failed running [/bin/sh -c docker-php-ext-install pdo pdo_mysql zip]: exit code: 1
ERROR: Service 'app' failed to build : Build failed
composer.json
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.4|^8.0",
"alexusmai/laravel-file-manager": "^2.5",
"ecrmnn/lorem": "^1.0",
"fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^1.0",
"guzzlehttp/guzzle": "^7.0.1",
"intervention/image": "^2.6",
"joshtronic/php-loremipsum": "^1.0",
"laravel/framework": "^8.0",
"laravel/tinker": "^2.0",
"laravel/ui": "^3.2",
"laravelcollective/html": "^6.1"
},
"require-dev": {
"facade/ignition": "^2.3.6",
"mockery/mockery": "^1.3.1",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.0"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"platform-check": false
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
}
}
Dockerfile
FROM php:8.0
RUN apt-get update -y && apt-get install -y openssl zip unzip git
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN docker-php-ext-install pdo pdo_mysql zip
WORKDIR /app
COPY . /app
RUN composer install
CMD php artisan serve --host=0.0.0.0 --port=8181
EXPOSE 8181
running docker-compose build
Solution 1:[1]
alexusmai/laravel-file-manager v2.5.4 requires ext-zip
This means that you need to install the zip extension [1].
nette/schema v1.2.1 requires php >=7.1 <8.1 -> your php version (8.1.3)
This means your packages are not compatible with php version 8.1. You are installing php 8.1.3 because you use FROM php:8 which takes the latest version.
So change your Dockerfile to something like
FROM php:8.0
# ...
RUN docker-php-ext-install pdo pdo_mysql zip
# ...
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 | Ron van der Heijden |
