none
Enter-PSSession to Nanoserver container in Docker -> Access is Denied

    Question

  • Hi,

    I've been pulling my hair out over this for the last few days and am really hoping someone here can help (or claim my StackOverflow bounty).

    I am hosting the microsoft/nanoserver image in a container within docker on Windows Server 2016 (basically following these instructions) with the command:

    docker run -it microsoft/nanoserver cmd

    This provides me an interactive command line within the container and I am able to ping the container from the host.

    However, when I try to use the command "Enter-PSSession -ComputerName <ipaddress | name in hosts file> -Credential ~\Administrator" to establish a remote powershell session with the nanoserver container I *always* receive the error "Access is denied".

    Here's what I have tried. After each test I have re-issued the Enter-PSSession command above but still get "Access is denied"

    * Setting the Administrator password from within the container with the command "net user Administrator <password>"

    * Calling "Set-WSManQuickConfig" from powershell within the container results in:

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    WinRM Quick Configuration
    Running the Set-WSManQuickConfig command has significant security implications, as it enables remote management through
     the WinRM service on this computer.
    This command:
     1. Checks whether the WinRM service is running. If the WinRM service is not running, the service is started.
     2. Sets the WinRM service startup type to automatic.
     3. Creates a listener to accept requests on any IP address. By default, the transport is HTTP.
     4. Enables a firewall exception for WS-Management traffic.
     5. Enables Kerberos and Negotiate service authentication.
    Do you want to enable remote management through the WinRM service on this computer?
    [Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): Y
    WinRM is already set up to receive requests on this computer.
    WinRM has been updated for remote management.
    Configured LocalAccountTokenFilterPolicy to grant administrative rights remotely to local users.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    NOTE: 'Enable-PSRemoting' and 'winrm quickconfig' are not available within nanoserver.

    * Enabling all PSSession configurations with the command 'Enable-PSSessionConfiguration -Name *' results in:

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    WinRM is already set up to receive requests on this computer.
    WinRM is already set up for remote management on this computer.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    * Navigating wsman: to do the following on both the client and server (restarting winrm service after every change)

    1. Allow basic authentication

    2. Allow non-encrypted communication

    3. Add "Everyone" with full-control to the RootSDDL of the wsman service

    * Adding transparent bridge to docker and starting container with 'docker run -it -network TransparentBridge microsoft/nanoserver cmd' and repeating all the above.

    * And a number of other things I've since forgot.

    I can telnet to port 5985 of the container so I know the firewall isn't an issue. Also I get a "HTTP BAD REQUEST" when passing it garbage so I know there's a service listening here.

    I have successfully set up nanoserver within a virtual machine (following these instructions) and can easily establish a remote powershell session with this server so I'm at a bit of a loss why it won't work with the docker image.

    Any help gratefully appreciated.

    Thanks,  Ian

    Monday, December 19, 2016 5:04 PM

All replies

  • I have the exact same issue. Did you resolve it?
    Friday, March 03, 2017 2:06 PM
  • Thursday, March 16, 2017 4:21 PM
  • Did you manage to resolve this. I have the exact same issue. Would be really happy if you share your solution
    Thursday, April 13, 2017 8:04 PM
  • Did you tried to follow this article?

    https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/deploy-containers-on-nano

    Add the Nano Server system to trusted hosts of the remote system. Replace the IP Address with the IP Address of the Nano Server.

    Copy
    none
    Set-Item WSMan:\localhost\Client\TrustedHosts 192.168.1.50 -Force
    

    Create the remote PowerShell session.

    Copy
    none
    Enter-PSSession -ComputerName 192.168.1.50 -Credential ~\Administrator
    

    When these steps have been completed, you will be in remote PowerShell session with the Nano Server system. The remainder of this document, unless noted otherwise, will take place from the remote session.

    • Proposed as answer by Myles Keating Friday, April 21, 2017 5:20 PM
    Friday, April 21, 2017 3:57 PM
  • Didn't work for me. Still getting access denied errors in nanoserver and servercore containers.

    I've exposed the WINRM ports, set Administrator password. I also added Nanoserver IP as a trusted host but nothing seems to work.
    Saturday, April 29, 2017 4:11 AM
  • Just checking are you able to connect to the the containers using:

    docker exec -it <containerid> <command> 

    (i.e.: docker exec 12345565 powershell) ?

    once you setup the administrator password did you enable it? net user administratror  /ACTIVE:YES

    Also notice the Enter-psession  as also a switch for containers -containerid did you alos tried with that?

    Thursday, May 04, 2017 8:55 AM
  • Okay I think I've got it ... when you run Enter-pssession the id need to be complete and not the alias showed by docker ps.

    Try this:

    1) docker inspect <RUNNINGCONTAINERID>

    2) look at the beginning the result for the complete ID

    3) Enter-pssesion -containerid <completeid> -runAsAdministrator (to enter as containeradministrator)

    or

    3) Enter-pssesion -containerid <completeid> (to enter as container user)

    • Proposed as answer by alefesta Thursday, May 04, 2017 2:00 PM
    Thursday, May 04, 2017 1:59 PM