ThreeMammals / Ocelot

.NET API Gateway

Home Page:https://www.nuget.org/packages/Ocelot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Access to the path '/app/ocelot.json' is denied

MuhammadAshouri opened this issue · comments

I'm using ocelot in dotnet 8
Running app on windows (self host) is totally fine
But when I run app in docker container I'm getting access denied in AddJsonFile
I've checked container folders and /app/ocelot.json is present (but it's read-only)

Here is my Program.cs

builder.Configuration
    .SetBasePath(environment.ContentRootPath).AddJsonFile("ocelot.json", false, true)
    .AddOcelot(environment)
    .AddEnvironmentVariables();
builder.Services
    .AddOcelot(configuration);

and even when I'm trying to remove read-only attribute I'm getting the same error

var file = new FileInfo("ocelot.json")
{
    IsReadOnly = false
};
file.CopyTo(Path.Combine(environment.ContentRootPath, "ocelot.json"), true);

I've already checked issues and haven't find the solution except this #1216 which seems like it isn't finished yet

Specifications

  • Version: 22.0.1
  • Platform: Docker (WSL)
  • Subsystem: Windows

Hi Muhammad!
Welcome to Ocelot world! 🐯

I can't get it, is it a bug or do you ask the question "How to configure"?
What I see now is misconfiguration issue... Your Program.cs code is very short!

Please upload whole solution to GitHub for review, or attach more artifacts: JSON config, Ocelot Startup C# code, and Ocelot app logs with errors/exceptions.
Configuration feature docs:

  • Configuration, you have to read all subsections carefully
  • Routing, it helps to write correct route definition JSON

But when I run app in docker container I'm getting access denied in AddJsonFile

Yeap, setup of Docker environment is out of the scope of Ocelot. But, I agree that we don't have much documentation on how to properly run Ocelot in a Docker environment: Search for "docker".
Seems, we need to write more documentation for Docker. But for now, you could refer to Microsoft Learn docs looking for Kestrel & Docker articles.


I've checked container folders and /app/ocelot.json is present (but it's read-only)

This is Linux OS in Docker environment issue (WSL is Linux, aka Ubuntu Linux build). Please refer to Linux or Ubuntu documentation, or read more docs for WSL setup.
If you will still be sure that this Ocelot issue when can't write Ocelot file to Linux OS drive then let us know how we could fix this.