Install the composer/composer container:
1 | $ 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.
1 2 3 4 5 | { "require" : { "monolog/monolog" : ">=1.0.0" } } |
Run Composer through the Composer container:
1 | $ docker run -- rm - v $( pwd ): /app composer /composer install |
Or run using a specific version of Composer:
1 | $ 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:
1 | $ 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
1 | $ sudo vim /usr/local/bin/composer |
The contents of the file will look like this:
1 2 3 4 | #!/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
1 | $ sudo chmod +x /usr/local/bin/composer |
Now the composer command is available native on host:
1 | $ composer --version |
实例 用composer安装coaster cms
1 | docker run -- rm --privileged - v $( pwd ): /app composer /composer create-project web-feet /coastercms |