Getting below error using docker-compose up on macOS -
/Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/AddIns/docker/MonoDevelop.Docker/MSbuild/Sdks/Microsoft.Docker.Sdk/build/Microsoft.VisualStudio.Docker.Compose.targets(5,5): Error: The APPDATA variable is not set. Defaulting to a blank string. Removing dockercompose9508177338158005990_xyz_1 Removing dockercompose9508177338158005990_xyz_1 Building xyz Building xyz Recreating 886c8806b528_dockercompose9508177338158005990_xyz_1 ... Recreating 57afcf6f0cb0_dockercompose9508177338158005990_xyz_1 ... Recreating 886c8806b528_dockercompose9508177338158005990_xyz_1 ... error ERROR: for 886c8806b528_dockercompose9508177338158005990_xyz_1 Cannot start service xyz: b'Mounts denied: \r\nThe paths /Microsoft/UserSecrets and /ASP.NET/Https\r\nare not shared from OS X and are not known to Docker.\r\nYou can configure shared paths from Docker -> Preferences... -> File Sharing.\r\nSee https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.\r\n.' Recreating 57afcf6f0cb0_dockercompose9508177338158005990_xyz_1 ... error ERROR: for 57afcf6f0cb0_dockercompose9508177338158005990_xyz_1 Cannot start service xyz: b'Mounts denied: \r\nThe paths /Microsoft/UserSecrets and /ASP.NET/Https\r\nare not shared from OS X and are not known to Docker.\r\nYou can configure shared paths from Docker -> Preferences... -> File Sharing.\r\nSee https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.\r\n.' ERROR: for xyz Cannot start service xyz: b'Mounts denied: \r\nThe paths /Microsoft/UserSecrets and /ASP.NET/Https\r\nare not shared from OS X and are not known to Docker.\r\nYou can configure shared paths from Docker -> Preferences... -> File Sharing.\r\nSee https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.\r\n.' ERROR: for xyz Cannot start service xyz: b'Mounts denied: \r\nThe paths /Microsoft/UserSecrets and /ASP.NET/Https\r\nare not shared from OS X and are not known to Docker.\r\nYou can configure shared paths from Docker -> Preferences... -> File Sharing.\r\nSee https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.\r\n.' Encountered errors while bringing up the project..
For more troubleshooting information, go to http://aka.ms/DockerToolsTroubleshooting (docker-compose)
Set a secret. Define an app secret consisting of a key and its value. The secret is associated with the project's UserSecretsId value. For example, run the following command from the directory in which the project file exists: .NET Core CLI. dotnet user-secrets set "Movies:ServiceApiKey" "12345".
Running dotnet user-secrets list displays the following message: No secrets configured for this application. To manage user secrets in Visual Studio, right click the project in solution explorer and select Manage User Secrets: See this issue for information on accessing user secrets from IIS.
The user secrets configuration provider registers the appropriate configuration source with the .NET Configuration API. ASP.NET Core web apps created with dotnet new or Visual Studio generate the following code: WebApplication.CreateBuilder initializes a new instance of the WebApplicationBuilder class with preconfigured defaults.
Secret Manager. The Secret Manager tool stores sensitive data during the development of an ASP.NET Core project. In this context, a piece of sensitive data is an app secret. App secrets are stored in a separate location from the project tree. The app secrets are associated with a specific project or shared across several projects.
This issue happens when you open, in Visual Studio for Mac, a project that was created using Visual Studio for Windows. Since most developers on my team are using Windows computers, I wanted to find a solution that would allow me to run the project without modifying its configuration. It required a lot of time and research, but I finally made it work:
Check if the folder ~/.aspnet/https
exists. If it does, skip to step 5.
Create the folder structure ~./asp.net/https
.
Run the command below to install the development certificates that allow you to access localhost
through HTTPS. More details here.
dotnet dev-certs https --trust
Run the command below to export the development certificate. Take note of the password as you will need it later:
dotnet dev-certs https -ep ${HOME}/.aspnet/https/FILE_NAME.pfx -p PASSWORD
Check if the folder ~/.microsoft/usersecrets
exists. If it does, it means you already have some User Secrets defined, so you can probably skip to step 7, otherwise, continue below.
Get the User Secrets ID for the Assembly of the Web Application you're building. It is usually located in a file named like Your.Project.Package.Name.Assembly.cs
. You can also search for UserSecrets.UserSecretsIdAttribute("
in your project folder and take the GUID.
You might need to repeat this step for multiple assemblies in your solution if you're using Docker Compose to deploy more than one Web application at the same time.
Inside ~./microsoft/usersecrets
, create a folder with the GUID you got on step 6, assuming one does not exist already. If it does, you can simply update the file secrets.json
inside it with the contents of the next step.
Create the file secrets.json
and insert the following:
{
"Kestrel": {
"Certificates": {
"Default": {
"Path": "/root/.aspnet/https/<FILE_NAME from Step 4>.pfx",
"Password": "<PASSWORD from Step 4>"
}
}
}
}
Create a file named .env
in the same folder where your Docker Compose configuration files are located inside the solution with the following content:
APPDATA=/Users/YOUR_USER_NAME
This file will be picked up by Docker Compose automatically when Visual Studio runs the tool.
Add the file .env
you just created to .gitignore
, so it doesn't get committed with your changes by mistake. This will ensure other developers with different environments can use this approach as well.
Create a symbolic link to point ~/ASP.NET
to .aspnet
as follows:
ln -s ~/.aspnet ~/ASP.NET
Create a symbolic link to point ~/ASP.NET/Https
to ~/.aspnet/https
as follows:
ln -s ~/.aspnet/https ~/ASP.NET/Https
Create a symbolic link to point ~/Microsoft
to ~/.microsoft
as follows:
ln -s ~/.microsoft ~/Microsoft
Create a symbolic link to point ~/Microsoft/UserSecretsto
~/.microsoft/usersecrets` as follows:
ln -s ~/.microsoft/usersecrets ~/Microsoft/UserSecrets
If you follow all steps correctly, Docker Compose will be able to resolve the Windows path in your Mac environment, find the required certificate password and run the solution correctly.
The outcome is that you only need to commit your .gitignore
changes to make sure your .env
file doesn't get included in the repo by mistake affecting others unintentionally - no further changes are required to the project.
Edit on August 4th, 2019: Some symlink creation parameters were in reverse order. Huge thanks to @BRBdot for pointing it out.
References:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With