microsoft / navcontainerhelper

Official Microsoft repository for BcContainerHelper, a PowerShell module, which makes it easier to work with Business Central Containers on Docker.
MIT License
389 stars 248 forks source link

Is it possible to create a Docker Container without using a hostname? #132

Closed Sven-Niehus closed 6 years ago

Sven-Niehus commented 6 years ago

Hi,

is it possible to create a Container without a hostname that can be accessed directly via its IP?

I'm creating new containers with the following command:

$additionalParameters = --hostname nav-test.anaptis.de --env clickonce=Y --env publicWebClientPort=443 --env publicFileSharePort=8080 --env publicSoapPort=7047 --env publicOdataPort=7048 --env publicWinClientPort=7046 --publish 80:80 --publish 443:443 --publish 8080:8080 --publish 7045:7045 --publish 7046:7046 --publish 7047:7047 --publish 7048:7048 --publish 7049:7049 --net=ext_wifi

New-NavContainer -accept_eula `
    -imageName microsoft/dynamics-nav:de `
    -containerName nav-test `
    -auth NavUserPassword `
    -additionalParameters $additionalParameters `
    -includeCSIDE `
    -doNotExportObjectsToText `
    -shortcuts Desktop `
    -memoryLimit 3G `
    -useSSL

docker inspect of a running container:

[
    {
        "Id": "41a1f8aa530393f07b14a1d04e86d948937a755c681e361766951ee2bd57cacf",
        "Created": "2018-05-15T08:44:20.884846Z",
        "Path": "powershell",
        "Args": [
            "-Command",
            "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';",
            ".\\Run\\start.ps1"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 2004,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2018-05-15T08:45:01.7309356Z",
            "FinishedAt": "0001-01-01T00:00:00Z",
            "Health": {
                "Status": "healthy",
                "FailingStreak": 0,
                "Log": [
                    {
                        "Start": "2018-05-15T10:45:31.7336217+02:00",
                        "End": "2018-05-15T10:45:33.144215+02:00",
                        "ExitCode": 0,
                        "Output": ""
                    },
                    {
                        "Start": "2018-05-15T10:46:03.1651408+02:00",
                        "End": "2018-05-15T10:46:13.1655235+02:00",
                        "ExitCode": -1,
                        "Output": "Health check exceeded timeout (10s)"
                    },
                    {
                        "Start": "2018-05-15T10:46:43.1860922+02:00",
                        "End": "2018-05-15T10:46:46.998775+02:00",
                        "ExitCode": 0,
                        "Output": ""
                    },
                    {
                        "Start": "2018-05-15T10:47:17.094734+02:00",
                        "End": "2018-05-15T10:47:19.5234245+02:00",
                        "ExitCode": 0,
                        "Output": ""
                    },
                    {
                        "Start": "2018-05-15T10:47:49.5542911+02:00",
                        "End": "2018-05-15T10:47:50.5831838+02:00",
                        "ExitCode": 0,
                        "Output": ""
                    }
                ]
            }
        },
        "Image": "sha256:eb627be31930413bff2fab075b415eed0d6cb26d48d2264fda7f3578a00087e0",
        "ResolvConfPath": "",
        "HostnamePath": "",
        "HostsPath": "",
        "LogPath": "C:\\ProgramData\\Docker\\containers\\41a1f8aa530393f07b14a1d04e86d948937a755c681e361766951ee2bd57cacf\\41a1f8aa530393f07b14a1d04e86d948937a755c681e361766951ee2bd57cacf-json.log",
        "Name": "/nav-test",
        "RestartCount": 0,
        "Driver": "windowsfilter",
        "Platform": "windows",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "C:\\ProgramData\\NavContainerHelper:C:\\ProgramData\\NavContainerHelper",
                "C:\\ProgramData\\NavContainerHelper\\Extensions\\nav-test\\my:C:\\Run\\my",
                "C:\\ProgramData\\NavContainerHelper\\Extensions\\nav-test\\Program Files:C:\\navpfiles"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "ext_wifi",
            "PortBindings": {
                "443/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "443"
                    }
                ],
                "7045/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "7045"
                    }
                ],
                "7046/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "7046"
                    }
                ],
                "7047/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "7047"
                    }
                ],
                "7048/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "7048"
                    }
                ],
                "7049/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "7049"
                    }
                ],
                "80/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "80"
                    }
                ],
                "8080/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "8080"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "unless-stopped",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 0,
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "hyperv",
            "CpuShares": 0,
            "Memory": 3221225472,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Data": {
                "dir": "C:\\ProgramData\\Docker\\windowsfilter\\41a1f8aa530393f07b14a1d04e86d948937a755c681e361766951ee2bd57cacf"
            },
            "Name": "windowsfilter"
        },
        "Mounts": [
            {
                "Type": "bind",
                "Source": "c:\\programdata\\navcontainerhelper",
                "Destination": "c:\\programdata\\navcontainerhelper",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            },
            {
                "Type": "bind",
                "Source": "c:\\programdata\\navcontainerhelper\\extensions\\nav-test\\my",
                "Destination": "c:\\run\\my",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            },
            {
                "Type": "bind",
                "Source": "c:\\programdata\\navcontainerhelper\\extensions\\nav-test\\program files",
                "Destination": "c:\\navpfiles",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],
        "Config": {
            "Hostname": "nav-test.anaptis.de",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "1433/tcp": {},
                "443/tcp": {},
                "7045/tcp": {},
                "7046/tcp": {},
                "7047/tcp": {},
                "7048/tcp": {},
                "7049/tcp": {},
                "80/tcp": {},
                "8080/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "databaseInstance=",
                "useSSL=Y",
                "securePassword=76492d1116743f0423413b16050a5345MgB8AEYAbwBiAFYAdwB2ACsAdQBBADQAQgBFAGkAMQBLADcAcABGAEcAaABRAEEAPQA9AHwAZAAxADgAYwAxADMAOQAxADQAMAAwAGYAZgAxADUAOQBhAGEANgA0ADMAZABhADUANAA2AGYANQA1ADIAZABjAA==",
                "publicWebClientPort=443",
                "username=admin",
                "passwordKeyFile=c:\\run\\my\\aes.key",
                "removePasswordKeyFile=Y",
                "clickonce=Y",
                "ExitOnError=N",
                "publicFileSharePort=8080",
                "publicSoapPort=7047",
                "publicWinClientPort=7046",
                "accept_eula=Y",
                "auth=NavUserPassword",
                "locale=de-DE",
                "licenseFile=",
                "databaseServer=",
                "publicOdataPort=7048",
                "NAVDVDURL=https://nav2016wswe0.blob.core.windows.net/dvd/9e144954-82e9-469e-a44a-2e73eeb16ed3",
                "VSIXURL=https://nav2016wswe0.blob.core.windows.net/dvd/al-0.12.17720.vsix",
                "DatabaseName=CronusDE",
                "COUNTRYURL=https://nav2016wswe0.blob.core.windows.net/dvd/32c004c7-fa1c-4a9d-adfa-44c472f8d5a7"
            ],
            "Cmd": [
                "powershell",
                "-Command",
                "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';",
                ".\\Run\\start.ps1"
            ],
            "Healthcheck": {
                "Test": [
                    "CMD",
                    "powershell",
                    ".\\Run\\HealthCheck.ps1"
                ],
                "Interval": 30000000000,
                "Timeout": 10000000000
            },
            "ArgsEscaped": true,
            "Image": "microsoft/dynamics-nav:de",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "country": "de",
                "created": "201804121443",
                "cu": "cu4",
                "eula": "https://go.microsoft.com/fwlink/?linkid=861843",
                "legal": "http://go.microsoft.com/fwlink/?LinkId=826604",
                "maintainer": "Dynamics SMB",
                "nav": "2018",
                "osversion": "10.0.14393.2125",
                "tag": "0.0.5.6",
                "version": "11.0.21441.0"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "41a1f8aa530393f07b14a1d04e86d948937a755c681e361766951ee2bd57cacf",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "1433/tcp": null,
                "443/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "443"
                    }
                ],
                "7045/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "7045"
                    }
                ],
                "7046/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "7046"
                    }
                ],
                "7047/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "7047"
                    }
                ],
                "7048/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "7048"
                    }
                ],
                "7049/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "7049"
                    }
                ],
                "80/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "80"
                    }
                ],
                "8080/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "8080"
                    }
                ]
            },
            "SandboxKey": "41a1f8aa530393f07b14a1d04e86d948937a755c681e361766951ee2bd57cacf",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "ext_wifi": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "41a1f8aa5303"
                    ],
                    "NetworkID": "5354406e0aa7404bb9609580450255ad127e1956f565e8dc8a14ef1a007ca7a4",
                    "EndpointID": "c32e65bdf4d9cda8ae2af947516e6dd95067b087c6b5799536f258b1e56e3283",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "00:15:5d:0d:80:94",
                    "DriverOpts": null
                }
            }
        }
    }
]

log of a newly created container:

Initializing...
Starting Container
Hostname is nav-test.anaptis.de
PublicDnsName is nav-test.anaptis.de
Using NavUserPassword Authentication
Starting Local SQL Server
Starting Internet Information Server
Creating Self Signed Certificate
Self Signed Certificate Thumbprint C94458B89CEBF29BB65FB3A908F3ABABB06D7C63
Modifying Service Tier Config File with Instance Specific Settings
Starting NAV Service Tier
Creating DotNetCore Web Server Instance
Creating http download site
Creating Windows user admin
Setting SA Password and enabling SA
Creating admin as SQL User and add to sysadmin
Creating SUPER user
WARNING: The password that you entered does not meet the minimum requirements. 
It should be at least 8 characters long and contain at least one uppercase 
letter, one lowercase letter, and one number.
Creating ClickOnce Manifest
Container IP Address: 192.168.192.197
Container Hostname  : nav-test.anaptis.de
Container Dns Name  : nav-test.anaptis.de
Web Client          : https://nav-test.anaptis.de:443/NAV/
Dev. Server         : https://nav-test.anaptis.de
Dev. ServerInstance : NAV
ClickOnce Manifest  : http://nav-test.anaptis.de:8080/NAV
2018-05-15T08:47:10.893002100Z 
Files:
http://nav-test.anaptis.de:8080/al-0.12.17720.vsix
http://nav-test.anaptis.de:8080/certificate.cer
2018-05-15T08:47:10.918526300Z 
Initialization took 106 seconds
Ready for connections!

The containers ipconfig:

Welcome to the NAV Container PowerShell prompt

PS C:\run> ipconfig

Windows IP Configuration

Ethernet adapter Ethernet 2:

   Connection-specific DNS Suffix  . : anaptis.de
   Link-local IPv6 Address . . . . . : fe80::a422:4755:c850:158d%5
   IPv4 Address. . . . . . . . . . . : 192.168.192.197
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.192.254

I want to use a transparent network as the containers network so that it can get its own IP via our DHCP server.

My networks:

NETWORK ID          NAME                DRIVER              SCOPE
22a9a03926f6        Standardswitch      ics                 local
5354406e0aa7        ext_wifi            transparent         local
3ab0ea101752        nat                 nat                 local
1de66a0b716e        none                null                local

inspect of ext_wifi:

[
    {
        "Name": "ext_wifi",
        "Id": "5354406e0aa7404bb9609580450255ad127e1956f565e8dc8a14ef1a007ca7a4",
        "Created": "2018-05-15T10:10:05.6930971+02:00",
        "Scope": "local",
        "Driver": "transparent",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "windows",
            "Options": null,
            "Config": [
                {
                    "Subnet": "0.0.0.0/0"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {
            "com.docker.network.windowsshim.hnsid": "d1b0dd20-0008-4f5e-ae99-add284eba3f1",
            "com.docker.network.windowsshim.networkname": "ext_wifi"
        },
        "Labels": {}
    }
]

The problem now is that I can access the containers IP, but the hostname that I set will not resolve due to that our DNS server does not know the container and so the Windows Client and as well C/SIDE won't work on any Client. Is it also not possible to set the hostname to the IP that the container has (because it will be assigned via DHCP)

freddydk commented 6 years ago

Most DHCP servers can integrate to a DNS and make local hostname lookup work - why wouldn't this work in this case?

kine commented 6 years ago

May be problem is, that your container is not attached to the network (the Containers is empty in the network inspect, I expect that you have done it after the container was created). You need to use --network=ext_wifi (may be the --net=ext_wifi is not recognized correctly?) when creating the container. And in this case you do not need to use --publish parameters, because the ports will be available directly.

Sven-Niehus commented 6 years ago

@freddydk the dhcp server is configured to accept secure and insecure updates, but I somehow can't resolve the hostname of the container.

@kine the container is attached to the network. I've also already removed the --publish parameters. My network ext_wifi is an virtual switch that I created in the Hyper-V-Manager. Maybe this is a problem?

Here is the configuration after the interface gets an DHCP lease

Configuration for interface "Ethernet 2"
    DHCP enabled:                         Yes
    IP Address:                           192.168.192.13
    Subnet Prefix:                        192.168.192.0/24 (mask 255.255.255.0)
    Default Gateway:                      192.168.192.254
    Gateway Metric:                       0
    InterfaceMetric:                      25
    DNS servers configured through DHCP:  192.168.192.66
                                          192.168.192.56
                                          192.168.192.44
    Register with which suffix:           Primary only
    WINS servers configured through DHCP: None
freddydk commented 6 years ago

Yeah, I don't think you are looking for getting a computer (or container) without a name to work - you need to figure out how to get name resolution to work. Maybe the missing WINS configuration is part of the issue?

kine commented 6 years ago

Is the 192.168.192.xxx the expected network, on which your computer and others are? I want to make sure that you are really getting the address from DHCP server you expect, and not from the internal DHCP server of the docker or hyper-v or something...

Sven-Niehus commented 6 years ago

@kine yes that is the correct network.

@freddydk I don't think so. WINS is not being used anywhere in our network so it should not be a problem for Docker

kine commented 6 years ago

I am using docker running as virtual on VMWare without issue like that. I have created the network through docker network create tlan -d transparent

I only needed to enable promiscuous mode on the VMWare switch. For Hyper-V switch you need to use address spoofing through Get-VMNetworkAdapter -VMName <name of vm that is your container host> | set-VMNetworkAdapter -MacAddressSpoofing On (taken from https://social.msdn.microsoft.com/Forums/en-US/b09266b0-ac4e-424f-8757-c34547c4adb1/unable-to-ping-containers-created-with-transparent-network-from-other-hosts?forum=windowscontainers)

Until than the network communication is not ok and could lead to some issues. But it is just guess...

Sven-Niehus commented 6 years ago

I fixed the Issue by activating dynamic updates for the segment and IPv4 itself on the DHCP Server.

Beforehand it was only enabled for the DHCP segment and not IPv4 which should have worked but did not.