How to install PHP composer inside a docker container

Andre :

I try to work out a way to create a dev environment using docker and laravel.

I have the following 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
&& chmod -R o+rw laravel-master/bootstrap laravel-master/storage

Laravel requires composer to call composer dump-autoload when working with database migration. Therefore, I need composer inside the docker container.

I tried:

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

But when I call

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

It throws the following error:

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"

I would be more than happy for advice how I can add composer to the PATH within my dockerfile or what else I can do to surpass this error.

Thanks for your support. Also: this is the gitub repository if you need to see the docker-compose.yml file or anything else.

Brayan Caldera :

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

install php and composer inside jenkins container

(Docker) How to install dependencies, using separate Composer container, in WordPress container?

How to install homebrew on Ubuntu inside Docker container

How to install Docker inside my ubuntu container?

Running composer install in docker container

How to install PHP Composer on a Limesurvey Docker image

how to install/start docker engine service inside a docker container

How to install composer dependencies in a container?

composer cannot allocate memory inside container docker

failed to install composer packages in docker container

Docker, How to get a container IP inside another container in PHP?

How do I install mdbook using Cargo inside a Docker container?

How can I install Docker inside an alpine container?

How To Install PHP Composer via Docker And Use As If It Was Installed Locally?

php composer inside container lost vendor directory

How to install Composer with docker exec

How can I execute command inside a Docker container from a Composer image?

How to reload service configuration (php-fpm) inside a docker container?

How to run node js docker container using docker-composer to manage php app assets

Unable to install vim or nano inside docker container

pip install not working inside docker container

pip install inside running docker container

Ping won't install inside a Docker container

Install PHP composer in existing docker image

How to install USBIP in Docker Container

How to install python on a docker container

How to install supervisor in a docker container?

Docker container exits with code 0 after running composer install

How to run a Docker host inside a Docker container?