Docker insecure registries issue on Windows Server 2016

This is my daemon.json at C:\ProgramData\docker\config, it did not exist originally but I created manually and copied contents from my Windows 10 pro config file.

{
  "allow-nondistributable-artifacts": [
    "myregistry:5000"
  ],
  "experimental": true,
  "insecure-registries": [
    " myregistry:5000"
  ],
  "hosts": [
    "npipe:////./pipe/docker_engine_windows"
  ]
}

I am pulling a pre-build image from the registry but keep getting the error.

Pulling myContainer (myregistry:5000/mycontainer:v1)...
ERROR: Get https://myregistry:5000/v2/: http: server gave HTTP response to HTTPS client

I even tried setting insecure registries from command line flag

PS D:\workDir> dockerd --insecure-registry "myregistry:5000"
unable to configure the Docker daemon with file C:\ProgramData\docker\config\daemon.json: the following directives are specified both as a flag and in the configuration file: insecure-registries: (from flag: [myregistry:5000], from file: [myregistry:5000])

The registry server is Windows Server 2019
The same settings work fine on my Windows 10 pro machine. Only difference is that I have Docker Desktop installed on the Windows 10 machine. I am pretty new to Docker, so if I missed any info please let me know and I will edit my post and include it.

Edit: I am using also creating and using a context

docker context create  mycontext--docker "host=tcp://myregistry:2375"
docker context use mycontext

As I am using myregistry as a context I had insecure registry in the container itself, so it is self-referencing. That has fixed the issue. Any better way of doing it?

Could you solve it?

I noticed you have a space before the registry name in the daemon.json. Maybe this is why Docker did not recognize it. I don’t know if it matters. When you tried to set the insecure registry from command line you got an other error message because you tried to configure the same. Try to fix the json file by removing the space or remove the whole definition and try it from the command line. If it dosn’t work, then the reason must be something else but I have never configured Docker on a Windows Server.