Closed chrisdaiii closed 7 months ago
I found the problem, I was using the ICSharpCode.SharpZipLib library, and each entry in the tar archive needed to set permissions.
The value of the Mode attribute is an octal number indicating the read, write, and execute permissions for the file. The format of this value is the same as permissions in Linux file systems.
TarEntry.TarHeader.Mode = Convert.ToInt32("0755", 8);
@chrisdaiii could you elaborate a little more on the solution? Looks like you are using testcontainers?
How does the usage of ICSharpCode.SharpZipLib
affect the permissions of the appsettings file in the docker container?
I get the same error but I am not using this library. At least not as a direct dependency.
NVM. Removing USER $APP_UID
worked for me. I guess if this were a prod image it might be worthwhile to update the permissions for the non root user
What version of Docker.DotNet?:
Steps to reproduce the issue:
Dockerfile
What actually happened?: Unhandled exception. System.UnauthorizedAccessException: Access to the path '/app/appsettings.json' is denied. ---> System.IO.IOException: Permission denied --- End of inner exception stack trace --- at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirError) at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode, Boolean failForSymlink, Boolean& wasSymlink, Func$(String[] args) in /src/WebApplication1/Program.cs:line 1
4 createOpenException) at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, UnixFileMode openPermissions, Int64& fileLength, UnixFileMode& filePermissions, Boolean failForSymlink, Boolean& wasSymlink, Func
4 createOpenException) at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable1 unixCreateMode) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) at Microsoft.Extensions.Configuration.FileConfigurationProvider.<Load>g__OpenRead|6_0(IFileInfo fileInfo) at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload) at Microsoft.Extensions.Configuration.ConfigurationManager.AddSource(IConfigurationSource source) at Microsoft.Extensions.Configuration.ConfigurationManager.Microsoft.Extensions.Configuration.IConfigurationBuilder.Add(IConfigurationSource source) at Microsoft.Extensions.Hosting.HostingHostBuilderExtensions.ApplyDefaultAppConfiguration(HostBuilderContext hostingContext, IConfigurationBuilder appConfigBuilder, String[] args) at Microsoft.Extensions.Hosting.HostApplicationBuilder..ctor(HostApplicationBuilderSettings settings) at Microsoft.AspNetCore.Builder.WebApplicationBuilder..ctor(WebApplicationOptions options, Action
1 configureDefaults) at Microsoft.AspNetCore.Builder.WebApplication.CreateBuilder(String[] args) at Program.Additional information: The main reason is because .net8 uses non-root user, but there is no problem when I use docker cli.