当我运行此命令时 docker build -t my_image
我将其作为输出
Sending build context to Docker daemon 2.048kB
Step 1/5 : FROM php:7.2-apache
---> f046c4ead123
Step 2/5 : MAINTAINER JLT 7 <j*******t.******@gmail.com>
---> Using cache
---> 2d04942bf1f3
Step 3/5 : RUN apt-get update
---> Using cache
---> 8f5c190e13ab
Step 4/5 : CMD ["echo","Hello World!!!...My frst message"]
---> Using cache
---> 9d67b4f4cf85
Step 5/5 : EXPOSE 8090
---> Using cache
---> 7ad8354944b2
Successfully built 7ad8354944b2
Successfully tagged my_image:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
但是当我在服务器上运行此端口时,它没有响应...
答案 0 :(得分:1)
EXPOSE
Dockerfile指令本身不会发布容器的端口(请参阅Dockerfile reference section in the documentation;该指令仅将元数据添加到您构建的映像中,并允许您指示容器的哪些端口。容器中运行的服务会监听。
EXPOSE
指令是可选,即使不设置该端口,您也可以连接到容器正在侦听的端口。
为了使端口可访问;
php:7.2-apache
映像,listens on port 80 by default 0.0.0.0
),而不是localhost / 127.0.0.1
(因为本地主机是容器< / em>,这意味着如果您的服务在localhost上侦听,则只能从容器本身内部进行访问) -p
/ --publish
选项具有简写形式和高级语法;我将在示例中使用速记语法。该表示法使用的格式为:-p <host-port>:<container-port>
例如,如果您的容器正在侦听端口80
,并且您想将该端口发布(或“映射”)到主机上的端口8090
;
docker run -d -p 8090:80 myimage
您现在可以在以下位置到达您的容器:
http://<ip-address of your host>:8090
http://localhost:8090