Public | Automated Build

Last pushed: 6 months ago
Short Description
Composer: Dependency Manager for PHP
Full Description

Supported tags and respective Dockerfile links

  • 1.0
  • 1.0-alpine
  • 1.0-php5
  • 1.0-php5-alpine
  • 1.1, 1, latest
  • 1.1-php5, 1-php5, php5
  • 1.1-alpine, 1-alpine, alpine
  • 1.1-php5-alpine, 1-php5-alpine, php5-alpine
  • master
  • master-php5
  • master-alpine
  • master-php5-alpine

What is Composer?

Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

wikipedia.org/wiki/Composer (software))

How to use this image.

Installation / Usage

  1. Install the composer/composer container:

     $ docker pull composer/composer
    

    Alternatively, pull a specific version of composer/composer:

     $ docker pull composer/composer:1.1
    
  2. Create a composer.json defining your dependencies. Note that this example is
    a short version for applications that are not meant to be published as packages
    themselves. To create libraries/packages please read the
    documentation.

     {
         "require": {
             "monolog/monolog": ">=1.0.0"
         }
     }
    
  3. Run Composer through the Composer container:

     $ docker run --rm -v $(pwd):/app composer/composer install
    

    Or run using a specific version of Composer:

     $ docker run --rm -v $(pwd):/app composer/composer:1.1 install
    

    If working with packages installed via git ssh the local .ssh directory shall be mapped into the container:

     $ docker run --rm -v $(pwd):/app -v ~/.ssh:/root/.ssh composer/composer install
    
  4. Add optional composer command to the host (tested on OS X El Capitan with docker-machine)

    Create new composer file

     $ sudo vim /usr/local/bin/composer
    

    The contents of the file will look like this:

     #!/bin/sh
     export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
     echo "Current working directory: '"$(pwd)"'"
     docker run --rm -v $(pwd):/app -v ~/.ssh:/root/.ssh composer/composer $@
    

    Once the script has been made, it must be set as executable

     $ sudo chmod +x /usr/local/bin/composer
    

    Now the composer command is available native on host:

     $ composer --version
    

Image Variants

composer/composer:<version>

This is the defacto image. If you are unsure about what your needs are, you probably want to use this one. It is designed to be used both as a throw away container (mount your source code and start the container to start your app), as well as the base to build other images off of.

composer/composer:php5

This is made to run Composer through PHP 5, rather then the default of PHP 7.

composer/composer:alpine

This image is based on the popular Alpine Linux project, available in the alpine official image. Alpine Linux is much smaller than most distribution base images (~5MB), and thus leads to much slimmer images in general.

composer/composer:php5-alpine

This is made to run Composer through PHP 5, rather then the default of PHP 7, through the Alpine container.

Docker Pull Command
Owner
composer
Source Repository

Comments (28)
libasoles
12 days ago

As already mentioned, to get this working in docker-compose.yml you must use this structure:
https://github.com/RobLoach/docker-composer/issues/88#issuecomment-229213544

composer:
    image: composer/composer
    volumes_from: 
       - php <- name of your php block
    working_dir: /var/www/html

Notice I had to declare the volume as an array.

mayconfsbrito
2 months ago

I've changed the response from the solution in this thread (https://github.com/RobLoach/docker-composer/issues/88#issuecomment-229213544) suggested by @otravers, adding the docker-compose file location in my docker folder:

#!/bin/sh
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
echo "Current working directory: '"$(pwd)"'"
docker-compose -f /path_to_docker-compose_file/docker-compose.yml run composer $@

And I've inserted the volumes_from and working_dir for my cluster config in my docker-compose.yml file:

composer:
image: composer/composer
volumes_from: php
working_dir: /var/www/

daigakusei
6 months ago

I have a problem to connect to an private mecurial repository in our company intranet.
The only error i receive is:

[RuntimeException]
Failed to execute hg clone 'ssh://composer@mercurial.company.com://mnt/sdb1/hg/dbo' '/app/vendor/company/dbo'
abort: no suitable response from remote hg!

From logfiles on the mercurial server the ssh tunnel is established with out errors, but no more logs.

I have extend the composer/composer:1.1-alpine image by this dockerfile.

FROM composer/composer:1.1-alpine
RUN composer self-update
RUN apk add --update mercurial

Has anyone here used this image on an private mercurial repository in intranet without services like bitbucket ?

otravers
6 months ago

I struggled with docker-compose, finally figured out thanks to this comment: https://github.com/RobLoach/docker-composer/issues/88#issuecomment-229213544

prhost
8 months ago

the composer of the folder inside the container is at the root /composer/ for anyone who wants to know.

jesmunrod
8 months ago

@pstankie
Call composer with --ignore-platform-reqs flag, example:

docker run --rm -v $(pwd):/app composer/composer update -o -vv --ignore-platform-reqs

meotimdihia
9 months ago

About akosgluebe's question. This is my concern too.
And i can't think simple resolution

keikeizhang
9 months ago

Who is in china
Be a friend
WeChat zhangchuang0816

pstankie
10 months ago

Somehow composer on fresh installation uses php 7.0.6 and returns:
Problem 1

- Installation request for ocramius/proxy-manager 2.0.2 -> satisfiable by ocramius/proxy-manager[2.0.2].
- ocramius/proxy-manager 2.0.2 requires php 7.0.0 - 7.0.5 || ^7.0.7 -> your PHP version (7.0.6) does not satisfy that requirement.

Problem 2

- ocramius/proxy-manager 2.0.2 requires php 7.0.0 - 7.0.5 || ^7.0.7 -> your PHP version (7.0.6) does not satisfy that requirement.
- doctrine/migrations 1.4.1 requires ocramius/proxy-manager ^1.0|^2.0 -> satisfiable by ocramius/proxy-manager[2.0.2].
- Installation request for doctrine/migrations 1.4.1 -> satisfiable by doctrine/migrations[1.4.1].
akosgluebe
a year ago

Hello,

It is shown how to make an alias: "Now the composer command is available native on host". Great.
How could I make this alias/this command available in a running container? Lets say I start up, for example, the latest jenkins container (or whatever other container), how could I use this composer inside that container? (I would like to avoid docker in docker)
Thanks!