Problem of maping localhost port number to Docker container inside Dockerfile

Hii

This is my Docker file looks like for tomcat image

ENV env dev
ENV name chetan
EXPOSE 8080:8080
CMD [“catalina.sh”, “run”]

The problem I’m facing is that port 8080 that is defined inside my Dockerfile is cannot able to map with my localhost machine can anyone please tell my EXPOSE 8080:8080 ? is correct or not?

I have to write this everytime

docker run -itd -p 8080:8080 my_tomat_image

I want that port 8080 that is defined inside my docker file is mapped with my localhost automatically I don’t need to define -p 8080:8080 when I run the docker image using docker run command

Should be EXPOSE 8080

I have done this but my localhost couldn’t be mapped with my container port

Did you try -P
it will map the exposed port from the docker file EXPOSE Automagically. I think it tries to match the port, but iff it can’t I think it picks an open port…
Also did you check that the port is not in use before deploy?

Can you show use the ouput of docker ps -a. I am currious if the container actualy keeps running…

Thanks for replay but after my research what I found is that there is no way to map my localhost port to the container port in Docker file that only expose the port but for mapping I have to pass argument inside docker run command there is no alternative for this thing

nope docker containers are not running as docker port doesn’t mapped to localhost

There is no such thing as a mapping inside a Dockerfile.
EXPORT is merly an instruction with documentation character… it does absolutly nothing :wink:

1 Like

You need to do this in a compose file. Under your service, you can have something like:
ports:
- “8080:80”
to map the internal port 80 to 8080 on the host.

oky thnx Iet me try this