php脚本将在Docker Localhost上运行
我是Docker的新手,所以请原谅我对此犯的任何技术措辞错误。
我正在尝试获得一个非常基本的“ Hello World!” PHP脚本通过Localhost Docker容器运行。我正在尝试运行此脚本以测试包含PHP和Oracle的图像: https> https: //hub.docker.com/r/silencesys/php-oci8
我使用以下命令将其拉动:docker pull silencesys/php-oci8,
然后我试图用许多命令来运行它,其中一些给我这个:
[16-Jun-2022 17:57:12] NOTICE: fpm is running, pid 1
[16-Jun-2022 17:57:12] NOTICE: ready to handle connections
然后其中一些给出了随机的字母和数字。我不知道它指的是什么,但我知道这意味着它正在运行容器。当我打开容器的终端并运行“ LS”时,我可以看到我的index.php文件。我什至可以运行“ cat index.php”,看到它在其中包含适当的代码来运行“ Hello World!”我什至将在此处以理智检查中包含代码:
<?php
echo "Hello World!";
?>
但是,每当我在浏览器中打开Localhost时,我都会得到此:
This page isn’t working right now
localhost didn’t send any data.
ERR_EMPTY_RESPONSE
我尝试了此基本docker Run命令的许多变体,我发现了在这里:
docker run -d -p 80:80 --rm --name temp-container -v "$PWD":/var/www/html silencesys/php-oci8
非常感谢任何帮助!
I am very new to Docker so please forgive any technical wording mistakes I make regarding this.
I am trying to get a very basic "Hello World!" php script to run through a localhost docker container. I am trying to run this script to test out this image that contains php and oracle: https://hub.docker.com/r/silencesys/php-oci8
I pulled it using this command: docker pull silencesys/php-oci8
Then I tried to run it with numerous commands, some of them giving me this:
[16-Jun-2022 17:57:12] NOTICE: fpm is running, pid 1
[16-Jun-2022 17:57:12] NOTICE: ready to handle connections
And then some of them give a random string of letters and numbers. I don't know what it refers to but I know that it means that it is running the container. When I open the container's terminal and run 'ls' I can see my index.php file. I can even run 'cat index.php' and see that it contains the proper code in there to run "Hello World!" I will even include the code in here as a sanity check:
<?php
echo "Hello World!";
?>
But everytime that I open up the localhost in my browser, I get this:
This page isn’t working right now
localhost didn’t send any data.
ERR_EMPTY_RESPONSE
I have tried so many variations of this base docker run command that I found here:
docker run -d -p 80:80 --rm --name temp-container -v "$PWD":/var/www/html silencesys/php-oci8
Any help is greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您所引用的Docker映像确实包含PHP,但不包含Web服务器。
使用PHP服务网页的服务器由Web服务器软件组成,该软件接受HTTP重新要求并在需要时在后台运行的PHP通信。可以考虑浏览器和PHP之间的中介,如果缺少浏览器,则无法访问您的PHP脚本。
我还没有找到可以立即帮助您的图像,但是我偶然发现了 this ,它告诉您,对于您的用语酶,您应该选择 php image 已包括Apache(即标签中的名称将包含
apache
)。The docker image you are referring to does contain PHP, but it does not contain a web server.
Servers that serve web pages using PHP consist of a webserver software, that accepts HTTP-requests and communicates to PHP running in the background if needed. It can be thought of an intermediary between the Browser and PHP, and if it is missing the browser cannot access your PHP script.
I haven't found an image that could help you right away, however I stumbled upon this, and it tells that for your usecase you should go for a PHP image that has Apache included (i.e. the name will contain
apache
in the tag).我解决的方式是通过使用此 image 使用我在问题中使用的图像。这是我所做工作的逐步指南:
在家中创建文件夹/[用户名]目录
docker拉soivangoi/nginx-php-adminer-oci8
docker拉silencesys/php-oci8
docker run -dit -p 8080:80 soivangoi/nginx-php-adminer-oci8 -v“ $ pwd”:/var/var/www/www/www/silencesys/silencesys/php-oci8
4.1。如果那不起作用,请尝试此“ Docker Run -D -IT -P 8080:80 -V” $ PWD“:/var/www/www/silencesys/php -oci8”
docker run -it -it -p 8080:80 -rm -name test-container -v“ $ pwd”:/var/www/soivangoi/nginx-php-adminer-oci8
bash进入容器中。通过命令行或单击容器上的终端按钮。
cd存储的php代码的位置。
运行它!
只要确保您使用的任何网络都可以访问Oracle数据库,否则它将不允许您运行代码。
The way I solved this was by using this image in conjunction with the image I was using in the Question. Here is a step by step guide of what I did:
Create folder in home/[username] directory
docker pull soivangoi/nginx-php-adminer-oci8
docker pull silencesys/php-oci8
docker run -dit -p 8080:80 soivangoi/nginx-php-adminer-oci8 -v "$PWD":/var/www/ silencesys/php-oci8
4.1. If that doesn't work try this "docker run -d -it -p 8080:80 -v "$PWD":/var/www/ silencesys/php-oci8"
docker run -it -p 8080:80 --rm --name test-container -v "$PWD":/var/www/ soivangoi/nginx-php-adminer-oci8
Bash into the container. Either by command line or by clicking the terminal button on the container.
cd to where your php code is stored.
Run it!
Just make sure that whatever network you are on has access to the oracle database or else it will not let you run your code still.