0

I am specifying PORT 80 in Spring boot application.properties like this server.port=80 So when running on localhost, this runs on port 80

Now I need to run it in a docker container and I did some hit and trial on the port mapping.

docker run -d -p 80:8080 DOCKERHUB_REPO/DOCKER_IMAGE

Then I did

docker run -d -p 80:80 DOCKERHUB_REPO/DOCKER_IMAGE

None of these worked. How should I proceed? Any help would be highly appreciated. Thanks

theanilpaudel
  • 3,348
  • 8
  • 39
  • 67

1 Answers1

1

I think first of all you should make sure that the application within the docker container indeed starts on port 80.

docker exec -it <process_id> bash

curl http://localhost:80/<somthing, some reset or actuator if you have it>

Once you have it set, make sure you've specified EXPOSE 80 in Dockerfile. Read the accepted answer to understand what exacly is -p and EXPOSE options are doing.

Now, running with -p is good, but maybe you don't have permissions to access port 80. In order to eliminate the docker related issues from the picture I suggest to test with another port which is more than 1024, something like 8080 for example. If it works (with Expose and -p options) than its security on the host machine for sure

Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97