Skip to content

Instantly share code, notes, and snippets.

@ricventu
Last active March 22, 2023 07:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricventu/897c76544c298bbc1f91521cc33f5fdf to your computer and use it in GitHub Desktop.
Save ricventu/897c76544c298bbc1f91521cc33f5fdf to your computer and use it in GitHub Desktop.
PHP command line through Docker

PHP command line through Docker

PHP

in .bashrc on in .zshrc insert:

function php() {
    docker run --rm --interactive --tty \
        --user $(id -u):$(id -g) \
        --volume "$(pwd)":/app \
        -w /app \
        php:8.2-cli-alpine php $@
}

then in the terminal you can user php as normal command line:

php -v

example:

 » php -v
PHP 8.2.4 (cli) (built: Mar 16 2023 22:00:14) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.4, Copyright (c) Zend Technologies

Composer

function composer() {
    docker run --rm --interactive --tty \
            --volume "$PWD":/app \
            --user $(id -u):$(id -g) \
            composer composer $@
}

then in the terminal you can user php as normal command line:

composer --version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment