Skip to content

Instantly share code, notes, and snippets.

@danmcadams
Created March 10, 2022 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danmcadams/ffd04ce334af6084c3abc66751ea31b9 to your computer and use it in GitHub Desktop.
Save danmcadams/ffd04ce334af6084c3abc66751ea31b9 to your computer and use it in GitHub Desktop.

Creating A Docker-powered Composer Alias

Create a simple composer alias with docker

Add this alias to the file containing your other aliases.

# This will use the latest composer version
alias composer='docker run --rm -it -v "${PWD}:/app" --user "$(id -u):$(id -g)" composer'

Add a Personal Access Token for GitHub

For light, everyday use, the above alias should work fine. If you run composer too many times in an hour, you may see an error saying your API limit has been reached and you need to provide an access token. To solve this, we need a personal access token for github. Here's how to do that.

  1. Go here to setup a token.
  2. Create a file called .auth.env in your ~/.composer directory. (if you don't have one, create it)
  3. Edit ~/.composer/.auth.env and put this line there
COMPOSER_AUTH={"github-oauth":{"github.com":"your_personal_access_token"}}

Add this alias to the file containing your other aliases. (modify or replace the original alias if you've already added it.)

# This will use the latest composer version
alias composer='docker run --rm -it -v ${PWD}:/app --user $(id -u):$(id -g) --env-file ~/.composer/.auth.env composer'

Update the Composer image

# Run this at any time to update your docker image to the lastest version of composer
alias update-composer='docker image rm composer:latest && composer --version'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment