Reputation: 21
I use a docker container to build C# appliaction.
The problem is that permission of the output files and dir (/bin and /obj) is "root"
I want the output of files not to be as a root user (I know the command chown but I want to get the files not as a root).
Example:
docker run --rm -v /home/user/d:/app -w /app mcr.microsoft.com/dotnet/sdk:3.1 dotnet publish
Upvotes: 0
Views: 1270
Reputation: 11
FROM mcr.microsoft.com/dotnet/sdk:6.0 as build
RUN mkdir ./app
RUN chmod 777 ./app
WORKDIR /app
COPY . .
RUN dotnet publish -c Release -o dist nameapp.csproj
FROM mcr.microsoft.com/dotnet/runtime:6.0 as runtime
COPY --from=build app/dist dist
ENTRYPOINT ["dotnet", "dist/nameapp.dll"]
Here is an example Dockerfile in case it helps you.
Upvotes: 0
Reputation: 136
With the default dotnet/sdk
this is not possible. But you can build your own container image and use it for building the application:
FROM mcr.microsoft.com/dotnet/sdk:3.1
ARG UID=1000
ARG GID=1000
RUN groupadd -g $GID user
RUN useradd -g $GID -u $UID -m -s /bin/bash user
USER user
WORKDIR /app
Build it with your uid
and gid
like this:
docker build <path to dir with Dockerfile> --build-arg UID=$(id -u) --build-arg GID=$(id -g) -t buildcontainer
This will build the image with a user user
that has the same uid and gid as your current user. You can then use the image instead of dotnet/sdk
to build the application:
docker run --rm -v /home/user/d:/app buildcontainer dotnet publish
Because uid and gid match between container and your environment outside the container, the output files will have the ownership that you expect.
Upvotes: 1