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'
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.
- Go here to setup a token.
- Create a file called
.auth.env
in your~/.composer
directory. (if you don't have one, create it) - 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'
# 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'