-
Maintained by:
Rob Bast, with contributions from the community. -
Where to get help:
the Docker Community Slack, Server Fault, Unix & Linux, or Stack Overflow
2.7.7
,2.7
,2
,latest
2.6.6
,2.6
2.5.8
,2.5
2.4.4
,2.4
2.3.10
,2.3
2.2.24
,2.2
,lts
1.10.27
,1.10
,1
-
Where to file issues:
https://github.com/composer/docker/issues -
Supported architectures: (more info)
amd64
,arm32v6
,arm32v7
,arm64v8
,i386
,ppc64le
,riscv64
,s390x
-
Published image artifact details:
repo-info repo'srepos/composer/
directory (history)
(image metadata, transfer size, etc) -
Image updates:
official-images repo'slibrary/composer
label
official-images repo'slibrary/composer
file (history) -
Source of this description:
docs repo'scomposer/
directory (history)
Composer is a tool for dependency management in PHP, written in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
You can read more about Composer in our official documentation.
$ docker run --rm --interactive --tty \
--volume $PWD:/app \
composer <command>
You can bind mount the Composer home directory from your host to the container to enable a persistent cache or share global configuration:
$ docker run --rm --interactive --tty \
--volume $PWD:/app \
--volume ${COMPOSER_HOME:-$HOME/.composer}:/tmp \
composer <command>
Note: this relies on the fact that the COMPOSER_HOME
value is set to /tmp
in the image by default.
Or if your environment follows the XDG specification:
$ docker run --rm --interactive --tty \
--env COMPOSER_HOME \
--env COMPOSER_CACHE_DIR \
--volume ${COMPOSER_HOME:-$HOME/.config/composer}:$COMPOSER_HOME \
--volume ${COMPOSER_CACHE_DIR:-$HOME/.cache/composer}:$COMPOSER_CACHE_DIR \
--volume $PWD:/app \
composer <command>
By default, Composer runs as root inside the container. This can lead to permission issues on your host filesystem. You can work around this by running the container with a different user:
$ docker run --rm --interactive --tty \
--volume $PWD:/app \
--user $(id -u):$(id -g) \
composer <command>
See: https://docs.docker.com/engine/reference/run/#user for details.
Note: Docker for Mac behaves differently and this tip might not apply to Docker for Mac users.
When you need to access private repositories, you will either need to share your configured credentials, or mount your ssh-agent
socket inside the running container:
$ eval $(ssh-agent); \
docker run --rm --interactive --tty \
--volume $PWD:/app \
--volume $SSH_AUTH_SOCK:/ssh-auth.sock \
--env SSH_AUTH_SOCK=/ssh-auth.sock \
composer <command>
Note: On OSX this requires Docker For Mac v2.2.0.0 or later, see docker/for-mac#410.
When combining the use of private repositories with running Composer as another user, you can run into non-existent user errors (thrown by ssh). To work around this, bind mount the host passwd and group files (read-only) into the container:
$ eval $(ssh-agent); \
docker run --rm --interactive --tty \
--volume $PWD:/app \
--volume $SSH_AUTH_SOCK:/ssh-auth.sock \
--volume /etc/passwd:/etc/passwd:ro \
--volume /etc/group:/etc/group:ro \
--env SSH_AUTH_SOCK=/ssh-auth.sock \
--user $(id -u):$(id -g) \
composer <command>
Our image is aimed at quickly running Composer without the need for having a PHP runtime installed on your host. You should not rely on the PHP version in our container. We do not provide a Composer image for each supported PHP version because we do not want to encourage using Composer as a base image or a production image.
We try to deliver an image that is as lean as possible, built for running Composer only. Sometimes dependencies or Composer scripts require the availability of certain PHP extensions.
Suggestions:
-
(optimal) create your own build image and install Composer inside it.
Note: Docker 17.05 introduced multi-stage builds, simplifying this enormously:
COPY --from=composer /usr/bin/composer /usr/bin/composer
-
(alternatively) specify the target platform / extension(s) in your
composer.json
:{ "config": { "platform": { "php": "MAJOR.MINOR.PATCH", "ext-something": "MAJOR.MINOR.PATCH" } } }
-
(discouraged) pass the
--ignore-platform-reqs
and / or--no-scripts
flags toinstall
orupdate
:$ docker run --rm --interactive --tty \ --volume $PWD:/app \ composer install --ignore-platform-reqs --no-scripts
View license information for the software contained in this image.
As with all Docker images, these likely also contain other software which may be under other licenses (such as Bash, etc from the base distribution, along with any direct or indirect dependencies of the primary software being contained).
Some additional license information which was able to be auto-detected might be found in the repo-info
repository's composer/
directory.
As for any pre-built image usage, it is the image user's responsibility to ensure that any use of this image complies with any relevant licenses for all software contained within.