如何安装 PHP 编辑器内的一个码头容器

我试图找到一种方法来创建一个开发环境使用 docker 和 laravel。

我有以下文件:

FROM php:7.1.3-fpm


RUN apt-get update && apt-get install -y libmcrypt-dev \
mysql-client libmagickwand-dev --no-install-recommends \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& docker-php-ext-install mcrypt pdo_mysql
&& chmod -R o+rw laravel-master/bootstrap laravel-master/storage

当处理数据库迁移时,Laravel 需要作曲家调用作曲家 dump-autoload,因此,我需要在 docker 容器中使用作曲家。

我试过:

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

但是当我打电话

docker-compose up
docker-compose exec app composer dump-autoload

它会抛出以下错误:

rpc error: code = 13 desc = invalid header field value "oci runtime error: exec failed: container_linux.go:247: starting container process caused \"exec: \\\"composer\\\": executable file not found in $PATH\"\n"

如果您能告诉我如何将作曲家添加到 dockerfile 中的 PATH 中,或者我还能做些什么来弥补这个错误,我将非常高兴。

谢谢你的支持。 另外: 如果您需要查看 docker-compose. yml 文件或其他内容,这个是 gitub 存储库。

170841 次浏览

We have basicly the same command running with the difference,

--install-dir=/usr/local/bin

Alternatively, you should add the composer bin files path to the $PATH variable.

export PATH=$PATH":/usr/bin"

Create an executable of your composer file using

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

I can install composer adding this line on my test dockerfile:

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

Here is the dockerfile:

FROM php:7.1.3-fpm


RUN apt-get update && apt-get install -y libmcrypt-dev \
mysql-client libmagickwand-dev --no-install-recommends \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& docker-php-ext-install mcrypt pdo_mysql


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

It works for me, to test if the composer are installed i access to my container bash and execute:

composer --version
Composer version 1.6.5 2018-05-04 11:44:59

In Dockerfile :

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

I'd just like to suggest another way.

Dockerfile:

RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer
FROM php:7.3-fpm-alpine
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli


RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer
RUN apk update
RUN apk upgrade
RUN apk add bash
RUN alias composer='php /usr/bin/composer'

This is how i do it with Laravel 8.4 in 2021 to deploy it to CloudRun in Google Cloud:

Dockerfile

#Get Composer
FROM composer:2.0 as vendor


WORKDIR /app


COPY database/ database/
COPY composer.json composer.json
COPY composer.lock composer.lock


RUN composer install \
--no-interaction \
--no-plugins \
--no-scripts \
--no-dev \
--prefer-dist


COPY . .
RUN composer dump-autoload

// some more custom steps like

FROM node:14.9 as frontend
...
FROM php:7.4-fpm
...

// Copy Composer dependencies

# Copy Composer dependencies
COPY --from=vendor app/vendor/ ./vendor/
COPY . .

// Some more custom steps

...

End of my Dockerfile to launch app with cleared optimized cache

# Run Laravel commands
RUN php artisan optimize:clear


CMD php artisan serve --host=0.0.0.0 --port=8080


EXPOSE 8080

My problem solved. I just stopped firewalld service on system

use composer in dockerfile using curl

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

Dockerfile

FROM 8.1.4-fpm


RUN apt-get update && apt-get install -y \
git \
curl \
zip \
unzip


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


WORKDIR /var/www