Skip to the content.

PHP-CLI Example

Content of index.php

<?php

echo "<h1>Hello from Docker !!!</h1>";
echo "<br>";
echo "PHP version:" . phpversion();

Content of Dockerfile

FROM php:7.0-cli
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
CMD [ "php", "./index.php" ]

Step 1

docker build -t $imagename .
# After each modification of the dockerfile
# the docker image needs to be recreated by running this code

Step 2

docker run -it --rm --name $containername $imagename
# Running the Docker image file

Refs: