Answer the question
In order to leave comments, you need to log in
How to do composer install inside a docker container?
I ran into a problem:
I need to prepare a ready-made environment during the build and, accordingly, I need the composer install command.
I am using docker compose:
...
php-bundle:
container_name: php_bundle
command: top -b
build: ./docker/php-bundle
depends_on:
- "php"
working_dir: /www
volumes:
- ./www:/www
networks:
client:
ipv4_address: 192.168.110.119
...
# https://hub.docker.com/_/php/
# PHP7-CLI
FROM php:7.1-cli
WORKDIR /www
RUN apt-get update -qq \
&& apt-get install -qy --no-install-recommends \
git \
openssl \
librecode0 \
uuid-dev \
libmagickwand-dev \
libsasl2-dev \
imagemagick \
libmagickwand-dev \
libmagickcore-dev \
libsqlite3-0 \
libxml2
RUN apt-get update -qq \
&& apt-get install -qy --no-install-recommends \
autoconf \
file \
g++ \
gcc \
libc-dev \
make \
cmake \
curl \
pkg-config \
libtool \
tar \
libmcrypt-dev \
libpng-dev \
zip \
unzip \
wget
RUN mkdir /var/log/php
RUN apt-get install -y libpq-dev \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql
RUN docker-php-ext-install \
gd \
mcrypt \
mysqli \
pdo \
pdo_pgsql \
pgsql \
pdo_mysql \
mbstring \
tokenizer \
opcache \
exif \
zip
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- \
--filename=composer \
--install-dir=/usr/local/bin && \
echo "alias composer='composer'" >> /root/.bashrc && \
composer
# Install phpunit
RUN wget https://phar.phpunit.de/phpunit-6.0.phar && \
chmod +x phpunit-6.0.phar && \
mv phpunit-6.0.phar /usr/local/bin/phpunit
# Install codecept
RUN wget http://codeception.com/codecept.phar && \
chmod +x codecept.phar && \
mv codecept.phar /usr/local/bin/codecept
RUN composer install --prefer-source --no-interaction
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Composer could not find a composer.json file in /www
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
Answer the question
In order to leave comments, you need to log in
COPY ./%относительный путь от Dockerfile%/composer.json /www/composer.json
RUN composer install --prefer-source --no-interaction
You can see working examples of using composer in docker in real projects. on github.
Mine for example:
https://github.com/FreeElephants/rest-auth/blob/ma...
https://github.com/FreeElephants/thruway-in-docker...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question