Search code examples
phpdockercodeigniterdocker-compose

composer not found for docker and codeigniter


This is all new to me. I am using Docker and CodeIgniter. I want to create an image for CodeIgniter in Docker. I am using Docker Desktop on Windows. I have a Dockerfile that contains the code below. When I run it, it works well till a point and throws an error, composer: not found. It executes the first 4 steps successfully until the error appears in the 5th step out of 9 steps.

This is my code for the Dockerfile which I got from an online tutorial.

FROM php:8.1.0-apache

RUN apt-get update \
    && apt-get install -y nano zip unzip git libicu-dev \
    && docker-php-ext-configure intl \
    && docker-php-ext-install intl \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

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

WORKDIR /var/www/html

RUN composer create-project codeigniter4/appstarter app --prefer-dist --stability=stable --no-progress --no-interaction

RUN chown -R www-data:www-data /var/www/html \
    && composer self-update

COPY codeigniter.conf /etc/apache2/sites-available/
RUN a2ensite codeigniter.conf \
    && service apache2 reload || true

RUN cd /etc/apache2/sites-available \
    && a2dissite 000-default.conf \
    && service apache2 reload || true

EXPOSE 80

I am using Docker Desktop and compose comes with it. On the command line, when I run the command "docker compose version", it shows "Docker Compose version v2.28.1-desktop.1" as the version that I have on my computer.

But when I run the command docker-compose up -d

I get the error message below. Can someone help me out please? I know it is referring to the Dockerfile code that I pasted above, but I am not sure of how to fix it as I already have composer.

=> => sha256:4b3248f455fea3a6577a6aadd5530530b0972512e5a13f7bbe455c5f3320c8da 245B / 245B 49.5s
=> => sha256:3e27fc6740deae2a2a872cfc43f56e9742d1b9c190ad7edae55cea58a58877fa 895B / 895B 50.1s
=> => extracting sha256:2c23b6beb07ab1b78af3929ff31a2ec34ece94ac611be50a32d54406e925b64f 7.1s
=> => extracting sha256:9874148cff9ac18f61ee23d041488694c002bf082e32d004232055b99e2f705f 0.0s
=> => extracting sha256:52defac986292394d78237bb5d79c9b45c18bcd31ba38ccf9a1c9fab6ee955b7 1.1s
=> => extracting sha256:585eed6f53992820a6d18df110b45f7a75a2d8b94fc827978b09e444ee3985dd 0.0s
=> => extracting sha256:aa83ee0498fff0d0660501ab49e185d11ce4952ccd2f64a982e2909f21163bcd 0.0s
=> => extracting sha256:ca8554b7b29aca11f30babbc12ca6b112261341f031b57b119c78e2137cd1d9b 0.2s
=> => extracting sha256:e2ce73d77ea79e033f9232d301bb900d4dc675733da9f16917eedd1d9466df20 0.0s
=> => extracting sha256:bbe0962a8cbafcf37eab4d505d3d1dc8b9f4c390df93f7841bfbe66c3d395f1c 1.0s
=> => extracting sha256:acfda1f63e3484bd437cf3611e53cae2b5ae5e72a3b417f886eb768f0ca09663 0.0s
=> => extracting sha256:4b3248f455fea3a6577a6aadd5530530b0972512e5a13f7bbe455c5f3320c8da 0.0s
=> => extracting sha256:3e27fc6740deae2a2a872cfc43f56e9742d1b9c190ad7edae55cea58a58877fa 0.0s
=> [db] exporting to image 0.1s
=> => exporting layers 0.0s
=> => writing image sha256:6eff5dd669da5c4558cf63f3ee935ed0b215245a24fdce3fc133c4c3e84b3665 0.0s
=> => naming to docker.io/library/codeigniter-project-db 0.0s
=> [web 2/9] RUN apt-get update && apt-get install -y nano zip unzip git libicu-dev && docker-php-ext-c 72.2s
=> [web 3/9] RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer 0.7s
=> [web 4/9] WORKDIR /var/www/html 0.1s
=> ERROR [web 5/9] RUN composer create-project codeigniter4/appstarter app --prefer-dist --stability=stable --no 0.4s
------
> [web 5/9] RUN composer create-project codeigniter4/appstarter app --prefer-dist --stability=stable --no-progress --no-interaction:
0.368 /bin/sh: 1: composer: not found
------
failed to solve: process "/bin/sh -c composer create-project codeigniter4/appstarter app --prefer-dist --stability=stable --no-progress --no-interaction" did not complete successfully: exit code: 127

I will appreciate your help.

Once again, thanks for your help. After adding the code you suggested. I run it again and got a new error message which I have pasted below.

...
=> CACHED [web stage-0  2/10] RUN apt-get update     && apt-get install -y nano zip unzip git libicu-dev     &&   0.0s => CACHED [web stage-0  3/10] RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --f  0.0s => CACHED [web stage-0  4/10] WORKDIR /var/www/html                                                               0.0s => [web stage-0  5/10] COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer                      0.1s => ERROR [web stage-0  6/10] RUN composer create-project codeigniter4/appstarter app --prefer-dist --stability=s  1.9s------ > [web stage-0  6/10] RUN composer create-project codeigniter4/appstarter app --prefer-dist --stability=stable --no-progress --no-interaction:1.091 Composer plugins have been disabled for safety in this non-interactive session.1.091 Set COMPOSER_ALLOW_SUPERUSER=1 if you want to allow plugins to run as root/super user.1.091 Do not run Composer as root/super user! See https://getcomposer.org/root for details1.105 Creating a "codeigniter4/appstarter" project at "./app"1.842 Plugins have been disabled automatically as you are running as root, this may be the cause of the following exception. See also https://getcomposer.org/root1.8531.868 In CurlDownloader.php line 371:1.8681.868   curl error 60 while downloading https://repo.packagist.org/packages.json: S1.868   SL certificate problem: unable to get local issuer certificate1.8691.8691.869 create-project [-s|--stability STABILITY] [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--repository REPOSITORY] [--repository-url REPOSITORY-URL] [--add-repository] [--dev] [--no-dev] [--no-custom-installers] [--no-scripts] [--no-progress] [--no-secure-http] [--keep-vcs] [--remove-vcs] [--no-install] [--no-audit] [--audit-format AUDIT-FORMAT] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--ask] [--] [<package> [<directory> [<version>]]]1.869------failed to solve: process "/bin/sh -c composer create-project codeigniter4/appstarter app --prefer-dist --stability=stable --no-progress --no-interaction" did not complete successfully: exit code: 100

Solution

  • Get Composer from Official Docker image with:

    COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer