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
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?
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
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.