I have a PHP script that needs to reference a variable I input at runtime. I have built a docker image (I cannot build the variable into the image as it changes each time):
Here's my minimum working example:
index.php
<?php
$name = $_ENV["name"];
echo $name;
?>
Dockerfile
FROM PHP:apache
COPY index.php /var/www/html
RUN chown -R www-data:www-data /var/www
CMD ["apache2-foreground"]
I'm trying to spin it up with:
docker run -d -p 80:80 myimage:latest -e name=James
However, this fails as apache seems to have a flag called -e which reads the log level.
I'm sure I'm missing something fairly simple here!
You need to put all the flag before the docker image name as anything after the image name will be treated as cmd when starting the docker container.
With that being said, please try to create the container using the following command
docker run -d -e name=James -p 80:80 myimage:latest
Please refer to this link for more info.