Control the versions using environment variables, put this in your .bashrc
or .zshrc
.
PHP_VERSION=7.1
NODE_VERSION=8.0
The shell functions below will run PHP, Composer, Node, NPM and Yarn using Docker, put these functions inside your .bashrc or .zshrc as well.
PHP
php () {
tty=
tty -s && tty=--tty
docker run \
$tty \
--interactive \
--rm \
--user $(id -u):$(id -g) \
--volume /etc/passwd:/etc/passwd:ro \
--volume /etc/group:/etc/group:ro \
--volume $(pwd):/code \
--workdir /code \
--publish 8000:8000 \
--publish 8080:8080 \
php:$PHP_VERSION-cli php "$@"
}
Composer
composer () {
tty=
tty -s && tty=--tty
docker run \
$tty \
--interactive \
--rm \
--user $(id -u):$(id -g) \
--volume /etc/passwd:/etc/passwd:ro \
--volume /etc/group:/etc/group:ro \
--volume $(pwd):/code \
--volume $HOME/.config/composer:/composer \
--workdir /code \
composer "$@"
}
PHPUnit
phpunit () {
php vendor/bin/phpunit "$@"
}
NodeJs
node () {
tty=
tty -s && tty=--tty
docker run \
$tty \
--interactive \
--rm \
--user $(id -u):$(id -g) \
--volume /etc/passwd:/etc/passwd:ro \
--volume /etc/group:/etc/group:ro \
--volume $(pwd):/code \
--workdir /code \
--publish 3000:3000 \
--publish 3030:3030 \
--publish 3333:3333 \
--publish 8000:8000 \
node:$NODE_VERSION node "$@"
}
NPM
npm () {
tty=
tty -s && tty=--tty
docker run \
$tty \
--interactive \
--rm \
--user $(id -u):$(id -g) \
--volume /etc/passwd:/etc/passwd:ro \
--volume /etc/group:/etc/group:ro \
--volume $HOME/.config:$HOME/.config \
--volume $HOME/.npm:$HOME/.npm \
--volume $(pwd):/code \
--workdir /code \
--entrypoint /usr/local/bin/npm \
--publish 3000:3000 \
--publish 3030:3030 \
--publish 3333:3333 \
--publish 8000:8000 \
node:$NODE_VERSION "$@"
}
YARN
yarn () {
yarnFile="$HOME/.yarnrc"
if [ ! -f $yarnFile ]; then
touch $yarnFile
fi
tty=
tty -s && tty=--tty
docker run \
$tty \
--interactive \
--rm \
--user $(id -u):$(id -g) \
--volume /etc/passwd:/etc/passwd:ro \
--volume /etc/group:/etc/group:ro \
--volume $HOME/.config:$HOME/.config \
--volume $HOME/.cache:$HOME/.cache \
--volume $yarnFile:$yarnFile \
--volume $(pwd):/code \
--workdir /code \
--entrypoint /usr/local/bin/yarn \
--publish 3000:3000 \
--publish 3030:3030 \
--publish 3333:3333 \
--publish 8000:8000 \
node:$NODE_VERSION "$@"
}
😍 good guy =)