I often run dockerised PHP apps, which have a standard password handling mechanism. A hash must be calculated:
<?php
$hash = password_hash("my_secret", PASSWORD_DEFAULT);
var_dump($hash);
I find it tedious to research how to do it each time, then create a throwaway .php
file, load it into a PHP container, etc., just to get that hash.
I want to run that inside the PHP container, inline in bash, something like this:
docker run --rm php:8.2-cli php '$hash = password_hash("my_secret", PASSWORD_DEFAULT); var_dump($hash);'
But that presumably expects a php file rather than inline php code, so produces error:
Could not open input file
I am not a PHP dev. How do I correct that docker run
command, so I don't have to get knee-deep in PHP?
UPDATE
This question was closed so I can't add an answer. For non-PHP devs like me, who wouldn't have thought to search for that linked answer (which doesn't mention the docker use case), but would have thought to search for this question (which does), the answer is is to use the -r
switch:
docker run --rm php:8.2-cli php -r '$hash = password_hash("my_secret", PASSWORD_DEFAULT); var_dump($hash);'
Thanks to @Nick for the solution in the comments below.