Skip to content

Instantly share code, notes, and snippets.

@hertz1
Created May 19, 2018 21:56
Show Gist options
  • Save hertz1/c402b041a73242c1bd948d9dbb88267d to your computer and use it in GitHub Desktop.
Save hertz1/c402b041a73242c1bd948d9dbb88267d to your computer and use it in GitHub Desktop.
Local PHP Composer Runtime for Docker Toolbox

Local PHP Composer Runtime for Docker Toolbox

Description

This is a simple PowerShell function that wrappers a call to docker-machine ssh so you can call composer as if it was installed on your host locally. It's not 100% functional, since it's not interactive (eg.: composer init will create the composer.json file, but will not ask you to fill in the fields. You can overpass this by passing the arguments like in the composer documentation.)

Instalation

  • Paste the contents of the file below into your PowerShell Profile. You haven't already, create one following these instructions.
  • Change the $composerTmpDir variable to the path where composer will store its caching and configuration files.

Usage

Use it like you would normally use composer:

PS C:\Users\MyUser>cd my-project
PS C:\Users\MyUser\my-project> composer install

That's it!

Fell free to leave any suggestions in the comments bellow or to fork it.

function _composer
{
$composerTmpDir = 'C:\Users\MyUser\.tmp'
$path = $pwd -replace "^C:\\", "/c/" -replace "\\", "/"
$tmpPath = $composerTmpDir -replace "^C:\\", "/c/" -replace "\\", "/"
$composerArgs = $args -join " "
$command = "docker run --interactive --user `$(id -u):`$(id -g) --rm -v '$path':/app -v '$tmpPath':/tmp composer $composerArgs"
docker-machine ssh default $command
}
New-Alias composer _composer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment