Reputation: 21
When I run this command docker build -t my_image .
I got this as an output:
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.
But when I run this port on the server it is not responding...
Upvotes: 0
Views: 129
Reputation: 29127
The EXPOSE
Dockerfile instruction by itself does not publish a container's ports (see the Dockerfile reference section in the documentation; the instruction only adds metadata to the image that you built, and allows you to give an indication which ports the service running in your container listens on.
The EXPOSE
instruction is optional, and even without setting that port, you are able to connect to a port that the container is listening on.
In order to make a port accessible;
php:7.2-apache
image, which listens on port 80 by default0.0.0.0
), and not on localhost / 127.0.0.1
(because localhost is "localhost" inside the container, which means that if your service is listening on localhost, it will only be accessible from inside the container itself)The -p
/ --publish
option has a shorthand, and an advanced syntax; I'll use the shorthand syntax in my examples; this notation is using the format: -p <host-port>:<container-port>
For example, if your container is listening on port 80
, and you want to publish (or "map") that port to port 8090
on your host;
docker run -d -p 8090:80 myimage
Your container can now be reached at:
http://<ip-address of your host>:8090
http://localhost:8090
Upvotes: 1