Official Repository

Last pushed: 7 days ago
Short Description
Composer is a dependency manager written in and for PHP.
Full Description

Supported tags and respective Dockerfile links

Quick reference

What is Composer?

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.

Using

Run the composer image:

docker run --rm --interactive --tty \
    --volume $PWD:/app \
    composer install

You can mount the Composer home directory from your host inside the Container to share caching and configuration files:

docker run --rm --interactive --tty \
    --volume $PWD:/app \
    --volume $COMPOSER_HOME:/composer \
    composer install

By default, Composer runs as root inside the container. This can lead to permission issues on your host filesystem. You can run Composer as your local user:

docker run --rm --interactive --tty \
    --volume $PWD:/app \
    --user $(id -u):$(id -g) \
    composer install

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:

docker run --rm --interactive --tty \
    --volume $PWD:/app \
    --volume $SSH_AUTH_SOCK:/ssh-auth.sock \
    --env SSH_AUTH_SOCK=/ssh-auth.sock \
    composer install

When combining the use of private repositories with running Composer as another (local) user, you might run into non-existant user errors. To work around this, simply mount the host passwd and group files (read-only) into the container:

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 \
    --user $(id -u):$(id -g) \
    --env SSH_AUTH_SOCK=/ssh-auth.sock \
    composer install

Suggestions

PHP Extensions

We strive to deliver an image that is as lean as possible, aimed at running Composer only.

Sometimes dependencies or Composer scripts require the availability of certain PHP extensions. In this scenario, you have two options:

  • Pass the --ignore-platform-reqs and --no-scripts flags to install or update:

    docker run --rm --interactive --tty \
       --volume $PWD:/app \
       composer install --ignore-platform-reqs --no-scripts
    
  • Create your own image (possibly by extending FROM composer).

Local runtime/binary

If you want to be able to run composer as if it was installed on your host locally, you can define the following function in your ~/.bashrc, ~/.zshrc or similar:

composer () {
    tty=
    tty -s && tty=--tty
    docker run \
        $tty \
        --interactive \
        --rm \
        --user $(id -u):$(id -g) \
        --volume /etc/passwd:/etc/passwd:ro \
        --volume /etc/group:/etc/group:ro \
        --volume $(pwd):/app \
        composer "$@"
}

License

View license information for the software contained in this image.

Docker Pull Command

Comments (3)
herloct
4 months ago

No update to 1.3.2??

alcohol
6 months ago

@fduarte42 I encourage you to read the documentation regarding --ignore-platform-reqs and also https://getcomposer.org/doc/06-config.md#platform

fduarte42
6 months ago

What is the meaning of this image? Shouldn't composer run with the same PHP version your project runs in? Say you have an PHP 5.6 application in one container and this image in another container, than the php dependecy would be of, right? And If you add a php 5.6 depndecy in your composer.json would this image even run?