0

(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' and http://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.

donquixote
  • 4,877
  • 3
  • 31
  • 54
  • Would work using the host network just for development for you? Then services are directly bound to host and therefore reachable from Browser and container the same. – araisch Feb 22 '23 at 22:35
  • @araisch Then I could curl to localhost:8081 from the container? ChatGPT suggested something similar, I had a quick test and it did not work immediately as suggested. But maybe it was just incomplete. One criterion is that others should be able to clone the project and have the same docker-compose setup, without too much custom configuration in the host system. And ideally this should also work in a testing pipeline. If you want to post an answer with this approach, go for it! Ideally with a minimal example docker-compose.yml file, and example curl commands. – donquixote Feb 22 '23 at 23:35

0 Answers0