这对我来说是全新的。我正在使用 Docker 和 CodeIgniter。我想在 Docker 中为 CodeIgniter 创建一个映像。我在 Windows 上使用 Docker Desktop。我有一个包含以下代码的 Dockerfile。当我运行它时,它在某种程度上运行良好并抛出错误,composer:未找到。它成功执行前 4 个步骤,直到 9 个步骤中的第 5 个步骤出现错误。
这是我从在线教程中获得的 Dockerfile 代码。
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
我正在使用 Docker Desktop,它附带了 compose。在命令行上,当我运行命令“docker compose version”时,它显示“Docker Compose version v2.28.1-desktop.1”作为我计算机上的版本。
但是当我运行命令 docker-compose up -d 时
我收到以下错误消息。有人可以帮我吗?我知道它指的是我上面粘贴的 Dockerfile 代码,但我不确定如何修复它,因为我已经有了 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
我将感谢您的帮助。
从官方 Docker 图像获取 Composer:
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer