Skip to content

Instantly share code, notes, and snippets.

@webarchitect609
Last active May 6, 2024 08:41
Show Gist options
  • Save webarchitect609/46c7a313a938cd7879af53be1137cc01 to your computer and use it in GitHub Desktop.
Save webarchitect609/46c7a313a938cd7879af53be1137cc01 to your computer and use it in GitHub Desktop.
Quick docker PHP 8 setup for composer and unit testing
# Terminal Tab #1 (with privileges inside container)
# =============
cd "/the/dir/you/want/to/work/with/php8"
docker run --name php8 \
-it \
-v $PWD:/var/php:rw \
php:8.0-cli-alpine3.12 \
ash
cd /tmp
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --quiet --install-dir="/usr/local/bin" --filename="composer" --2
php -r "unlink('composer-setup.php');"
apk update
apk add git
mkdir /home/php
# Terminal Tab #2 (with the same UID:GID inside container)
# ======================
docker exec -it \
-u $(id -u):$(id -g) \
php8 \
ash
HOME=/var/php
cd $HOME
# Then run composer install or any other command.
# Be prepared that composer can ask for a token to access git repo via ssh
# Clean when the work is done and the container is stopped
docker rm php8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment