Installation php dependencies with the composer docker

Composer not installed on the machine, it can be run with a docker: docker run

How can run in any directory it, bash can define the function of:

  1. Create a directory on the host, to save the composer's configuration and cache files:
mkdir ~/dnmp/composer
  1. Open the host ~/.bashrcor ~/.zshrcfile, add the following:
composer () {
    tty=
    tty -s && tty=--tty
    docker run \
        $tty \
        --interactive \
        --rm \
        --user $(id -u):$(id -g) \
        --volume ~/dnmp/composer:/tmp \
        --volume /etc/passwd:/etc/passwd:ro \
        --volume /etc/group:/etc/group:ro \
        --volume $(pwd):/app \
        composer "$@"
}
  1. Let onset file:
source ~/.bashrc
  1. In any directory on your host will be able to use composerthe:
cd ~/dnmp/www/
composer create-project yeszao/fastphp project --no-dev
  1. (Optional) If prompted to rely on, a --ignore-platform-reqs --no-scriptsclosed-dependent detection.
  2. (Optional) for the first time composerwill ~/dnmp/composergenerate a directory config.jsonfile, you can specify the domestic warehouse in this file, for example:
{
    "config": {},
    "repositories": {
        "packagist": {
            "type": "composer",
            "url": "https://packagist.laravel-china.org"
        }
    }
}

Guess you like

Origin www.cnblogs.com/clannadxr/p/11314977.html