How to set up Pint in Docker in less than 5 minutes
I have several legacy projects in Laravel and I can’t install pint in each one, I want to run pint in each one and make it independent of the system and the projects.
Steps:
1- Create the docker image and install pint
docker run --interactive --tty
--volume ~/.composer:/app
--volume ${COMPOSER_HOME:-$HOME/.composer}:/tmp
composer require laravel/pint
command breakdown:
— interactive: creates an interactive session that allows user interaction with the container
— tty: assigns a tty terminal for the interactive session
— volume ~/.composer:/app: mounts the ~/.composer directory of the host system to the /app directory of the archive. This allows the container to access the Composer files on the host.
— volume ${COMPOSER_HOME:-$HOME/.composer}:/tmp: mounts the Composer directory on the host to the /tmp directory of the container. This allows Composer to store temporary files on the host.
composer require laravel/pint: finally, use Composer to install the “laravel/pint” package in the container.
2- command to execute pint in our project:
docker run --rm -v ~/.composer:/app -v $(pwd):/app/project -w /app composer ./vendor/bin/pint ./project
— rm: this option tells Docker to delete the container after the command execution is finished.
-v ~/.composer:/app: this option mounts the ~/.composer directory on the host system to the /app directory of the container. This allows the container to access the Composer files on the host.
-v $(pwd):/app/project: this option mounts the current working directory ($(pwd)) of the host system to the /app/project directory of the container. This allows the container to access the project located in the current working directory.
-w /app: this option sets the current working directory inside the container to /app.
composer: this is the name of the container image that will be used to execute the command.
./vendor/bin/pint ./project: this is the command that will be executed inside the container. The pint command is a binary that is installed through the laravel/pint package, which must be available in the composer.json file of the project. This command will be executed in the /app/project directory inside the container.
Plus:
Create alias
open ~/.bashrc
add the following line
alias pintd='docker run --rm -v ~/.composer:/app -v $(pwd):/app/project -w /app composer ./vendor/bin/pint ./project'
save and run source ~/.bashrc