用php和docker创buildweb应用程序
我有以下的DOCKERFILE
:
FROM php RUN apt-get update && apt-get install -y git RUN git clone https://github.com/marcosh/webinthemiddle.git EXPOSE 80 CMD php -S localhost:80 webinthemiddle/index.php
我想用php创build一个非常基本的应用程序。
我使用sudo docker build -t marcosh/webinthemiddle .
构build图像sudo docker build -t marcosh/webinthemiddle .
然后我试着运行容器使用
sudo docker run -d -P marcosh/webinthemiddle
要么
sudo docker run -d -P marcosh/webinthemiddle php -S localhost:80 webinthemiddle/index.php
然后,我检查与sudo docker ps
哪个端口被映射到容器和浏览器的端口80 localhost:#PORT#
,但我什么都没有find…
我究竟做错了什么?
有两件事对你来说是很有帮助的:
- 在debugging这样的问题时,首先交互地在前台运行容器,并使用TTY(分别是
-i
和-t
)。 你的命令会像sudo docker run -i -t -P marcosh/webinthemiddle php -S localhost:80 webinthemiddle/index.php
。 - 接下来,在Docker容器世界中,
localhost
是容器的本地(不是你的主机)。 由于容器只在localhost
侦听,所以来自其他IP地址(比如你的主机)的请求将不会进入套接字。 你会想听取0.0.0.0:80
。