Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dockerfile expose port cannot telnet

Tags:

docker

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

like image 999
王奕然 Avatar asked Dec 04 '25 23:12

王奕然


2 Answers

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

like image 145
VonC Avatar answered Dec 06 '25 12:12

VonC


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>

like image 26
Savio Mathew Avatar answered Dec 06 '25 14:12

Savio Mathew