To run Windows Docker containers on your Macintosh computer, use the following setup. This will introduce a performance hit, because you run virtualization in virtualization.
Besides the usual setup process, you need to enable hypervisor applications to avoid the error
Error response from daemon: container … encountered an error during CreateContainer: failure in a Windows system call: No hypervisor is present on this system
Install VMware Fusion on your MacBook Pro
Create a Windows 10 virtual machine
Open the Settings of the Windows 10 virtual machine
Select Processors & Memory
In the Advanced region check Enable hypervisor applications in this virtual machine
The dotnet core MVC web application template adds the GDPR cookie acceptance message to the header of the page template. When the site is hosted with HTTP the accept button does not clear the message resulting an infinite loop, when the user cannot log in and the site continuously asks for the acceptance.
When the site is hosted in a Docker container it is also simpler to instal the SSL certificate on the load balancer and host the site with HTTP on port 80.
We use cookies. To be able to use this site please click the Accept button.
To remove the feature delete the
<partial name="_CookieConsentPartial" />
line from the Views\Shared\Layout.cshtml file.
Without the acknowledgement the dotnet core framework will not save any non essential cookies in the browser, so the session state will stop working.
To tell the dotnet core framework, that the application does not require the user to allow the saving of the cookies set the value of CheckConsentNeeded to false in the ConfigureServices() method, services.Configure<CookiePolicyOptions> { section
options.CheckConsentNeeded = context => false;
To make sure the session cookie is always saved even if the GDPR confirmation is enabled, declare it to essential in the ConfigureServices() method, services.AddSession(options => { section
It is not good practice to store secrets in the source code repository. The sample C# dotnet core application code stores the database connection string in the appsettings.json file which eventually will be pushed into GitHub. To follow the Twelve-Factor App methodology, store the configuration values in environment variables and load them runtime. This method enables your application to run in a Docker container and in a Kubernetes pod.
If the connection string is not specified, we get the error message
System.ArgumentNullException: ‘Value cannot be null. Parameter name: connectionString’
To read the connection string from an environment variable
Add the builders to the Startup.cs file
public Startup(IConfiguration configuration, IHostingEnvironment env)
{
Configuration = configuration;
Env = env;
// Read the connection string from the "ASPNETCORE_ConnectionStrings:DefaultConnection" environment variable
// RESTART Visual Studio if you add or edit environment variables for the change to take effect.
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
// This one needs to be last for the environment variables to have the highest priority
builder.AddEnvironmentVariables("ASPNETCORE_");
Configuration = builder.Build();
}
Create the ASPNETCORE_ConnectionStrings__DefaultConnection environment variable. The double underscore will be converted to a colon ( : ) . This variable name works on Windows, and also in Linux where the environment variable name cannot contain colons.
IMPORTANT: If you add or change an environment variable, restart Visual Studio for the change to take effect. It is not enough to restart the application.
docker: Error response from daemon: error while mounting volume ‘/var/lib/docker/volumes/…/_data’: failed to mount local volume: mount :/data:/var/lib/docker/volumes/…/_data, data: addr=…,vers=4: operation not permitted.
or
docker: Error response from daemon: error while mounting volume ‘/var/lib/docker/volumes/…/_data’: failed to mount local volume: mount :/data:/var/lib/docker/volumes/…/_data, data: addr=…,vers=4: connection refused.
To be able to mount the volume from macOS, use the insecure option in /etc/exports
PostgreSQL internally converts all column and table names to lowercase when executing the SQL query.
If the column or table name contains uppercase letters, we need to use double quotes to be able to reference them.
When we get the error message
ERROR: column “username” does not exist
select * from public.”AspNetUsers” where UserName = ‘… ^
HINT: Perhaps you meant to reference the column “AspNetUsers.UserName”. SQL state: 42703
The first line of the error message shows, that PostgreSQL internally converted UserName to username. To be able to reference the column, use double-quotes. If you reference the table name too, don’t copy the hint, make sure the table and column names are separate strings in double-quotes with a period between them.
select * from public."AspNetUsers" where "AspNetUsers"."UserName" = 'MY_VALUE';
Docker images are stored on the host to launch as fast as possible. The drawback is, Docker can fill the hard drive with unused images. A recent possible bug in Docker caused the accumulation of unused, unreferenced images on the host. To delete all Docker containers and images, use these commands in the terminal
Get the base line
# Get the free disk space
df -h
# List the running containers
docker ps
# List all containers
docker ps -a
# List the Docker images
docker images