(Different forms of this question exists elsewhere, but they do not address the specific requirement.)
Background / Motivation
I have a docker-compose setup with two containers:
- The first container "cas" contains, among other things, a mock server for CAS login. Currently available on
http://localhost:8080
. - The second container "web" has an application that uses the CAS server for login. Currently available on
http://localhost:8081
.
This setup is meant for development, and is meant to be shared with other developers.
The CAS login flow works as follows:
- Visitor goes to a login form in "web" container.
- Visitor is redirected to the login form in "cas" server.
- After completed CAS login, visitor is redirected back to the "web" server.
- The web server makes a curl request to the CAS server to validate the login.
The application has configuration options to define the url (hostname, port, path) of the CAS server. It will use the same url config value for client side redirects and for server-side curl requests. This is 3rd party code, so I would like to avoid modifying it.
This means:
- The client browser needs to be able to access the both containers. Currently they are available at
http://localhost:8080
for 'web' andhttp://localhost:8081
for 'cas'. - The 'web' container will make curl requests to 'cas' using the same url
http://localhost:8081
.
Question
I need a url for docker container 'cas' that is available both in curl from container 'web', and in the browser / from the host machine.
What I found so far
If I understand correctly, solutions proposed elsewhere require to use different urls for curl requests than in the browser. E.g. in the browser it would be http://localhost:8081
, but with curl it would be http://cas/
.
To make this work, I would have to modify the app to use a different CAS url on server side vs client side. I would like to avoid this.
E.g. accessing a docker container from another container
Notes
The CAS is an implementation detail, I think the problem is independent of that. I think the "from the browser" could be replaced with "from the host machine", for the solution it would be equivalent.