Reputation: 4059
i write dockerfile
EXPOSE 2181 2888 3888
and docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
abc644fe1ad0 00088267fb34 "/opt/startzookeeper…" 2 seconds ago Up 1 second 2181/tcp, 2888/tcp, 3888/tcp hopeful_curie
but when i telnet localhost 2181
Trying ::1... telnet: connect to address ::1: Connection refused Trying 127.0.0.1... telnet: connect to address 127.0.0.1: Connection refused telnet: Unable to connect to remote host
why i cannot telnet the exposed port? should i add what to dockerfile? thanks your any suggestion
Upvotes: 3
Views: 3084
Reputation: 787
The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime. You can specify whether the port listens on TCP or UDP, and the default is TCP if the protocol is not specified. The EXPOSE instruction does not actually publish the port. . To publish the port when running the container, use the -p flag on docker run to publish and map one or more ports, or the -P flag to publish all exposed ports and map them to high-order ports.
eg: docker run -d -p 2181:2181 <image>
Upvotes: 3
Reputation: 1328262
EXPOSE
is just a metadata added to the image (as noted in "Docker ports are not exposed").
It does not actually publish the port.
You need to make sure you docker run
the image with -p
option, in order to actually publish the container port to an host port.
-p=[]
Publish a container᾿s port or a range of ports to the host
format:ip:hostPort:containerPort
|ip::containerPort
|hostPort:containerPort
|containerPort
Upvotes: 4