Sign inSign up

mkenney/composer

By mkenney

Updated over 7 years ago

A small PHP Composer dependency manager image and a wrapper script that does not run as root

Image
1

3.5K

mkenney/composer repository overview

docker-badges.webbedlam.com

composer

MIT License stability-mature Build status Github issues Github pull requests

Portable composer dev and build tool.

Tagged Images

Images are tagged according to the installed PHP version.Please let me know if you need a particular version tagged.

latest Dockerfile

Based on php:7-cli-alpine. This image should be considered under development and may not be as stable as versioned images.

php7 Dockerfile

Based on php:7-cli-alpine.

php7.0 Dockerfile

Based on php:7.0-cli-alpine. This is the last version with mcrypt available.

php5 Dockerfile

Based on php:5-cli-alpine.

Installation

Essentially, this is just a shell script that manages a Composer docker image. The docker image includes a script (run-as-user) that allows commands to write files as either the current user or the owner/group of the current directory, which the shell scripts take advantage of to make sure files are created with your preferred permissions rather than root.

About

The source repository contains a shell script that wraps running a docker container to execute composer. The current directory is mounted into /src which is the location the composer command will run from. In order to facilitate access to private repositories or use public-key authentication, $HOME/.ssh is mounted into the container user's home directory. Any authentication issues that come up can most likely be resolved by modifying your $HOME/.ssh/config file.

A wrapper script (/run-as-user) is provided in the image that attempts to execute composer as the current user. If the $HOME/.ssh directory exists on the host, is mounted into the container properly and is not owned by root, then the wrapper script will execute composer as a user who's uid and gid matches those properties on that mounted directory. Otherwise, the wrapper script will execute composer as a user who's uid and gid matches those properties on the mounted /src directory (the current directory). This way composer files are installed as either the current user or as the project directory's owner/group instead of root or a random user.

Because this runs out of a Docker container, all files and directories required by your composer command must be available within the current directory. Specifying files or directories from other locations on the system will not work. For example, --working-dir=/home/user/folder/ would attempt to use the /home/user/folder/ path inside the container instead of on the host.

Images & Wrapper Scripts

This assumes that you already have Docker installed. A running docker daemon is required.

Installation is just a matter of putting the shell script somewhere in your path and making it executable. I like to put my scripts in a bin/ folder in my home directory:

$ wget -nv -O ~/bin/composer https://raw.githubusercontent.com/mkenney/docker-composer/master/bin/composer
$ chmod 0755 ~/bin/composer

The wrapper script defaults to the php7 tag, but specifying a different tag is easy. You can define the image tag you want to use in your environment which will set the default (you probably want to define this in your .bashrc or similar profile script):

export DOCKER_COMPOSER_TAG=php5

or you can easily specify it at runtime whenever necessary, for example:

$ DOCKER_COMPOSER_TAG=php5 composer install

If you would to see like additional modules, tags, and/or wrapper scripts added to this project please feel free to create an issue or open a pull request.

  • composer self-update

    The self-update command pulls down the latest docker image matching the current image tag and updates the shell script itself. If you don't have write permissions on the shell script you'll get a permissions error, you can run the self-update command with sudo if needed.

Tag summary

Content type

Image

Digest

Size

68.3 MB

Last updated

over 7 years ago

docker pull mkenney/composer