docker 使用composer

Install the composer/composer container:

 $ docker pull composer/composer

Alternatively, pull a specific version of composer/composer:

 $ docker pull composer/composer:1.1

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"
     }
 }

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

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

实例 用composer安装coaster cms

docker run --rm --privileged -v $(pwd):/app composer/composer create-project web-feet/coastercms