Skip to content

Instantly share code, notes, and snippets.

@daluamon
Forked from webarchitect609/php8_docker.sh
Created April 15, 2023 14:31
Show Gist options
  • Save daluamon/8a7d8ae472ed6dfd71114affce36b9cf to your computer and use it in GitHub Desktop.
Save daluamon/8a7d8ae472ed6dfd71114affce36b9cf 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