Tutorial: How to use Fief with Docker Compose along with other services #282
Replies: 3 comments 2 replies
-
Hail, @gabrielcnegre 👋 Welcome to Fief's kingdom! Our team will get back to you very soon to help. In the meantime, take a minute to star our repository ⭐️ Farewell! |
Beta Was this translation helpful? Give feedback.
-
@gabrielcnegre I really like what you are attempting to show here with Traefik, but your example is too incomplete; it's as if it is a snippet of a larger project and things were left out. For example:
IMHO: If you're going to post an example like this, it would be more helpful if it were a complete and working example rather than just some hints. I also looked to see if you had a public GitHub repo to see if this would be available there, but you don't have any public repos. I created a new Discussion post with my take on the Docker Compose and other files. Thanks for helping us all get a little further with this process. |
Beta Was this translation helpful? Give feedback.
-
Thank you! I'm deploying to k8s with traefik doing the routing. |
Beta Was this translation helpful? Give feedback.
-
Hey everyone,
I've been in the development field for several years, but surprisingly, this is my first contribution to a GitHub thread. I apologize if there are any procedural errors or if this isn't the optimal place to share this solution.
First and foremost, I'd like to express my gratitude for this project. I genuinely hope for its immense success.
Recently, I've been experimenting with Fief in one of my projects. I noticed there's been a significant amount of discussion on integrating Fief with Compose. The primary challenges revolve around how the Fief client authenticates in conjunction with Docker networking. In short, the keys and the openid configuration returned by the server are associated with the host. However, the internal service's API call host isn't identical to the host accessed from localhost (e.g., accessing a FastAPI service via a browser).
Some have suggested using ngrok as a solution, but I encountered challenges. The jwks, for instance, returns URI`s to http, which the client struggles to handle (since it gets redirected). Additionally, ngrok introduces other complications, like with OpenAPI docs. (mixed http/https sources)
The other idea was to change the docker networking to host, but this still did not work, since the origin host that calls the client is different that the one calling the API.
I've found a working solution: Traefik!
Since Traefik serves as a reverse proxy it allows you to configure routers to localhost subdomains. Subsequently, these subdomains can be directed to your machine's localhost (labeled "host-gateway") within the services, ensuring consistent hostnames.
.env
If you want to use FastAPI:
Now you can access Fief at "fief.localhost" and your api at "api.localhost".
Hope it helps! (Please feel free to ask anything or offer suggestions / improvements)
Beta Was this translation helpful? Give feedback.
All reactions