I have a spring boot service running in a docker container. I am using HttpServletRequest to get the remote IP address from incoming client request. This works as intended locally but once the service is running in a Docker container the IP that is grab is the Docker container IP instead of the clients IP. Is there a way to get around this and get the actual client IP? Any help would be most appreciated.
Here's more programmatic detail:
@GetMapping("/foo)
public ResponseEntity requestBar(HttpServletRequest request) {
String clientIp = request.getRemoteAddr();
//DO STUFF WITH IP
}
Above is an example GET request for "bar". Using HttpServletRequest you can get the remote address of the machine making the request. Running this locally (on a local machine non dockerized) the above works perfectly. The service obtains the client IP and I can verify that the IP is correct. Hosting the same service in Docker, calling getRemoteAddr() will give the containers default gateway IP. I hope this further explanation provides more clarity of what I'm trying to accomplish. As always, any and all help will be most appreciated.
UPDATE: Just clarify a few tidbits, the Spring Boot(v1.5.13) service runs on a Docker Host (Docker version 18.06.1-ce, build e68fc7a). What I mean by running locally is when I am starting up the service on my local machine during development. I use the latest version of Intellij for all my Java dev work. The service can be spun up using Intellij on my development machine.