Last active
May 6, 2024 08:41
-
-
Save webarchitect609/46c7a313a938cd7879af53be1137cc01 to your computer and use it in GitHub Desktop.
Quick docker PHP 8 setup for composer and unit testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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