dotnet restore error inside Docker-Container - permission denied - docker

I used this tutorial to put my asp.net Core Application inside a Docker Container
https://code.visualstudio.com/docs/containers/quickstart-aspnet-core
But get an permission Denied inside the container:
10:39:02 /usr/share/dotnet/sdk/3.1.201/NuGet.targets(124,5): error : Access to the path '/src/obj' is denied. [/src/Lankoon.csproj]
10:39:02 /usr/share/dotnet/sdk/3.1.201/NuGet.targets(124,5): error : Permission denied [/src/Lankoon.csproj]
10:39:02 The command '/bin/sh -c dotnet restore "./Lankoon.csproj"' returned a non-zero code: 1
I tried it on a Windows10 Machine and also on an Jenkins Build Server, the result is the same.
I don't understand as which user the nuget is running?
Can anyone help?

Add the following line to you dockerfile
USER root
The problem inside my container was that the user was not root and dotnet restore unfortunately need root access.

Related

verdaccio error 'verdaccio: types-registry'

I'm currently creating a private npm registry for my company.
I pulled the verdaccio docker container and I put the config.yaml file into the folders in the container.
When I run verdaccio, an error message comes up:
EACCES: permission denied, mkdir '/verdaccio/storage/types-registry'
I haven't written any lines for 'types-registry'.
Can someone help me solve this?

QNAP Container Station - Multiple dockers get Permission Denied

I run a QNAP TS-453a at home running Container Station on it. Suddenly multiple containers got some sort of error about "Permission Denied".
For example postgres\postgres returns:
error: exec failed: permission denied
nodered/node-red docker returns: exec ./entrypoint.sh: permission denied. And this continues in different forms for a total of 20 containers. Basically every container returns permission errors on the docker-entrypoint. I shared my docker.sock with 3 containers to maintain it: HomeAssistant, WatchTower and Portainer.
What I tried:
Recreate the container from scratch
Checked the permissions on the shared volumes
Reinstalled Container Station/Docker
Restart the QNAP NAS
sudo chmod 666 /var/run/docker.sock

Installing magento 2.2 on docker

I need help with magento installation on docker. I have created folder on desktop "development/sources/". After that in sources folder I have cloned repository https://github.com/php-cuong/docker-magento2-lamp. There is yaml file for docker configuration. After running docker-compose up -d command in cli, this error appears:
Recreating d817e559459e_mysql_service ...
Recreating d817e559459e_mysql_service ... error
ERROR: for d817e559459e_mysql_service Cannot start service mysql: error while creating mount source path '/C/User s/Denis/Desktop/development/sources': mkdir /C/Users/Denis/Desktop: permission denied
ERROR: for mysql Cannot start service mysql: error while creating mount source path '/C/Users/Denis/Desktop/devel opment/sources': mkdir /C/Users/Denis/Desktop: permission denied
Encountered errors while bringing up the project.
Mount source path that is listed in error above, was already created manually before I run that command.
permission denied
Right click on Docker icon in tray and select Settings.
Under "Shared Drives" mark drive "C" and apply.
Now it should work. If it doesn't, just restart Docker and it should be working.

How to solve permission denied inside docker container?

I am using the docker file for project API Sprout.
I want to launch the executable inside the docker container on a local file called open_api.json. Following the README, I run:
docker run -p 8000:8000 -v $(pwd)open_api.json:/api.json danielgtaylor/apisprout /api.json
But it fails with
[..datetime...] open /tmp/api.json: permission denied
How should I give the right permission / user to the file or container?
you need to give the api.json file the correct permissions.
for test give use:
chmod 777 api.json
. if it works change the permissions to something more restricted
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Step_by_Step_Guide/s1-navigating-ownership.html

Unable to load the service index for source https://api.nuget.org/v3/index.json. [C:\app\aspnetapp.csproj]

https://github.com/dotnet/dotnet-docker-samples/tree/master/aspnetapp
Docker command docker build -t aspnetapp.
I am getting an error for docker build command as
C:\Program Files\dotnet\sdk\2.1.105\NuGet.targets(104,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [C:\app\aspnetapp.csproj]
[1]PS C:\Users\pssharma\dotnet-docker-samples\aspnetapp> docker build -t aspnetapp .
Sending build context to Docker daemon 2.444MB
Step 1/10 : FROM microsoft/aspnetcore-build:2.0 AS build-env
---> eb21d939e0d8
Step 2/10 : WORKDIR /app
---> Using cache
---> d4ec30216ed7
Step 3/10 : COPY *.csproj ./
---> Using cache
---> 2ff39b5e6cb4
Step 4/10 : RUN dotnet restore
---> Running in 776764a35311
Restoring packages for C:\app\aspnetapp.csproj...
Restoring packages for C:\app\aspnetapp.csproj...
C:\Program Files\dotnet\sdk\2.1.105\NuGet.targets(104,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [C:\app\asp
C:\Program Files\dotnet\sdk\2.1.105\NuGet.targets(104,5): error : An error occurred while sending the request. [C:\app\aspnetapp.csproj]
C:\Program Files\dotnet\sdk\2.1.105\NuGet.targets(104,5): error : The operation timed out [C:\app\aspnetapp.csproj]
The following command returned a non-zero code: 1
powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; dotnet restore
This appears to happen when there are multiple network adaptors present for the host and the priority of said adaptor is misconfigured. Run the following to display a table of your network adaptors:
Get-NetIPInterface -AddressFamily IPv4 | Sort-Object -Property InterfaceMetric -Descending
You want your primary adaptor (in my case wifi) to have the lowest InterfaceMetric.
Set-NetIPInterface -InterfaceAlias 'Wi-Fi' -InterfaceMetric 1
My network adaptor table for reference:
See this github thread for more information:
https://github.com/docker/for-win/issues/2760#issuecomment-430889666
For me, this issue appeared randomly (along with multiple similar issues, such as "permission denied for nuget" etc. To fix that, restart Visual Studio)
For windows, it was fixed by restarting docker service and restarting Visual Studio (2017).
Shut down Docker and Visual Studio
Winkey + R, type in services.msc
Find Docker for Windows Service and restart it (restarting Docker normally is not enough)
Start Docker and Visual Studio
Just add --network=host option to docker build
docker build -t aspnetapp . --network=host
I got this working by passing in docker build environment variables from the command line like so:
docker build --build-arg HTTP_PROXY=http://{un}:{pw}#{proxyhost}:{port} --build-arg HTTPS_PROXY=http://{un}:{pw}#{proxyhost}:{port} -t aspnetapp .
*note that your username must be url encoded (ei. DOMAIN\name => DOMAIN%5Cname)
Had the same issue, the problem was a missing dependency used by NuGet.
I am using the microsoft/dotnet:sdk image, and it works after installing libcurl3 to my image.
Try adding
RUN apt-get update && apt-get install -y libcurl3
to your Dockerfile before restoring.
if it doesn't work, try restarting your Docker instance.
edit: if that doesn't help you, there is this open issue on the NuGet github where some people are trying to solve the same problem.
edit2:added Ignas solution: restarting docker instance.
I'm suprised no one said this already. This was caused by not having the latest sdk installed. In my case docker was looking for the file
C:\Program Files\dotnet\sdk\3.1.302\NuGet.targets
However this file did not exist on my machine instead I had a different minor version.
C:\Program Files\dotnet\sdk\3.1.301\NuGet.targets
I'm sure they're away to get it working using an older version, but in my case I just updated the downloaded the latest sdk
If the issue is caused by your organisation's self-signed certificates, you can fix it by:
Get the certificate file (*.cer) provided by your IT department.
Copy it into the SSL certificate location: COPY ["./combined.cer", "/etc/ssl/certs/"]
Update SSL cert list: RUN update-ca-certificates
These steps work for Debian, need to be adapted for other distros.
configuring the dns in the docker engine helped me
you go to docker setting then to docker engine you can see a json formatted doc
you add this :
"dns": ["10.0.0.2","8.8.8.8"]
then restart docker
i wish that helps you
Open CMD or Powershell and run: dotnet nuget locals http-cache --clear
https://status.nuget.org/
In my case, in Dockerfile, I have
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
and
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
But I only have .net 2.1 installed (view by dotnet --list-sdks). So I have to change 2.2 to 2.1 to make it work.
After one hour fighting with proxy, finally following solution worked just fine for me:
docker build --build-arg HTTP_PROXY=http://xxxx.com:8080 --build-arg HTTPS_PROXY=http://yyyy:8080 -t kdekarin/aspnet .
See #patrickbadley's comment for more info!
One more reason why this happens. If your docker file targeting windows container and your docker is running linux mode or vice versa.
I had the same issue on Debian 9. I fudge the error with disconnecting from local network. It works for me because I did not change anything on codebase and I do not need to get packages from nuget.
I got this resolved on my Windows 10 Machine by Disabling Avast Antivirus and unInstalling McAffee Antivirus.
Right click the Avast Icon in the Notification Tab
Select Avast Shields Control
Click on "Disable Until Computer is Restarted".
And you can now run the Docker Build Successfully.
I can give Further Assistance if needed.

Resources