I have the following dockerfile
:
FROM openjdk:8 as stage0
WORKDIR /opt/docker
COPY opt /opt
USER root
RUN ["chmod", "-R", "u=rX,g=rX", "/opt/docker"]
RUN ["chmod", "u+x,g+x", "/opt/docker/bin/sapmock"]
FROM openjdk:8
USER root
RUN id -u demiourgos728 2> /dev/null || (( getent group 0 || groupadd -g 0 root ) && useradd --system --create-home --uid 1001 --gid 0 demiourgos728 )
WORKDIR /opt/docker
COPY --from=stage0 --chown=demiourgos728:root /opt/docker /opt/docker
EXPOSE 8080
USER 1001:0
ENTRYPOINT ["/opt/docker/bin/sapmock"]
CMD []
as you can see, that exposes the port 8080
.
When I start to run a container from the image as the following:
docker run -it -p 8080:8080 db261ab225b5
Server online at localhost on the port 8080
Press RETURN to stop...
The client can not connect through the address localhost:8080
why?
It's possible that Rajesh's answer is correct. Although I think it's more likely that your application is just binding to
localhost
/127.0.0.1
inside the container, and that won't work. Make sure your app binds to0.0.0.0
inside the container then the port mapping will work.