docker/go-docker

panic: reflect: indirection through nil pointer to embedded struct when execute -SwitchDaemon during Packer run

Opened this issue · 0 comments

Description

I am trying to provision image for VM using Packer.
I install Docker during Packer run.
I want to switch daemon to windows and I get the error bellow.
I check in my code that Docker is installed and is running prior to switch to windows daemon. Both checks successful.

Steps to reproduce the issue:

This is how I check that Docker is running:

    $endTime = (Get-Date).AddSeconds($TimeoutInSeconds)
    do {
        $dockerdProcess = Get-Process dockerd -ErrorAction SilentlyContinue
        $dockerComService = Get-Process 'com.docker.service' -ErrorAction SilentlyContinue
        $dockerService = Get-Service -Name Docker -ErrorAction SilentlyContinue | Where-Object Status -eq 'Running'
        if(!$dockerdProcess -and !$dockerComService -and !$dockerService) {
            Start-Sleep -Milliseconds 500
        }
    } while($null -eq $dockerdProcess -and $null -eq $dockerComService -and $null -eq $dockerService -and ($endTime -gt (Get-Date)))

This is code that I execute to switch to windows Docker daemon:

    $dockerCli = Join-Path -Path $env:ProgramFiles -ChildPath 'Docker\Docker\DockerCli.exe'
    if(!(Test-Path -Path $dockerCli)) {
        throw "DockerCli not found: $dockerCli"
    }
    $dockerCliArgs = @('-SwitchDaemon')
    $dockerCliProcess = Start-Process -FilePath $dockerCli -ArgumentList $dockerCliArgs -PassThru -NoNewWindow -Wait -ErrorAction Stop
    if($dockerCliProcess.ExitCode -ne 0) {
        throw "Failed to switch Docker daemon. Exit Code: $($dockerCliProcess.ExitCode)"
    }

Error that I got after trying to switch to windows Docker daemon:

azure-arm: ### Switching Docker container mode to Windows...
azure-arm: panic: reflect: indirection through nil pointer to embedded struct [recovered]
azure-arm: 	panic: reflect: indirection through nil pointer to embedded struct
azure-arm: goroutine 1 [running]:
azure-arm: text/template.errRecover(0xc00045f2e8)
azure-arm: 	/usr/local/go/src/text/template/exec.go:169 +0x1c5
azure-arm: panic(0x21c32a0, 0x26feb40)
azure-arm: 	/usr/local/go/src/runtime/panic.go:965 +0x1c7
azure-arm: reflect.Value.FieldByIndex(0x2356660, 0xc00009e380, 0x99, 0xc00027c250, 0x2, 0x2, 0x0, 0x278e3e8, 0x21c32a0)
azure-arm: 	/usr/local/go/src/reflect/value.go:889 +0x325
azure-arm: text/template.(*state).evalField(0xc00045f258, 0x2356660, 0xc00009e380, 0x99, 0xc00004c0e3, 0x6, 0x2776578, 0xc0002c35f0, 0xc00030c540, 0x1, ...)
azure-arm: 	/usr/local/go/src/text/template/exec.go:616 +0x4ed
azure-arm: text/template.(*state).evalFieldChain(0xc00045f258, 0x2356660, 0xc00009e380, 0x99, 0x2356660, 0xc00009e380, 0x99, 0x2776578, 0xc0002c35f0, 0xc00030c530, ...)
azure-arm: 	/usr/local/go/src/text/template/exec.go:569 +0x227
azure-arm: text/template.(*state).evalFieldNode(0xc00045f258, 0x2356660, 0xc00009e380, 0x99, 0xc0002c35f0, 0xc00030c540, 0x1, 0x1, 0x224e5e0, 0x3543770, ...)
azure-arm: 	/usr/local/go/src/text/template/exec.go:533 +0x11a
azure-arm: text/template.(*state).evalCommand(0xc00045f258, 0x2356660, 0xc00009e380, 0x99, 0xc0002c35c0, 0x224e5e0, 0x3543770, 0x99, 0xd0, 0xc00055a1a0, ...)
azure-arm: 	/usr/local/go/src/text/template/exec.go:461 +0x8f0
azure-arm: text/template.(*state).evalPipeline(0xc00045f258, 0x2356660, 0xc00009e380, 0x99, 0xc0006c2900, 0x10a0176, 0xc0004445f8, 0xc00037ce80)
azure-arm: 	/usr/local/go/src/text/template/exec.go:435 +0x125
azure-arm: text/template.(*state).walk(0xc00045f258, 0x2356660, 0xc00009e380, 0x99, 0x2776380, 0xc0002c3620)
azure-arm: 	/usr/local/go/src/text/template/exec.go:254 +0x38a
azure-arm: text/template.(*state).walk(0xc00045f258, 0x2356660, 0xc00009e380, 0x99, 0x2776650, 0xc0002c3590)
azure-arm: 	/usr/local/go/src/text/template/exec.go:263 +0x13c
azure-arm: text/template.(*Template).execute(0xc00037ce80, 0x271e020, 0xc000141f20, 0x2356660, 0xc00009e380, 0x0, 0x0)
azure-arm: 	/usr/local/go/src/text/template/exec.go:217 +0x1c6
azure-arm: text/template.(*Template).Execute(...)
azure-arm: 	/usr/local/go/src/text/template/exec.go:200
azure-arm: github.com/docker/cli/cli/command/system.formatInfo(0x278a3c8, 0xc000107110, 0x0, 0xc00030c3b0, 0x1, 0x1, 0xc000444500, 0x0, 0x0, 0x0, ...)
azure-arm: 	/go/src/github.com/docker/cli/cli/command/system/info.go:511 +0x1fd
azure-arm: github.com/docker/cli/cli/command/system.runInfo(0xc000176dc0, 0x278a3c8, 0xc000107110, 0xc00018f9c0, 0x0, 0x0)
azure-arm: 	/go/src/github.com/docker/cli/cli/command/system/info.go:88 +0x3a5
azure-arm: github.com/docker/cli/cli/command/system.NewInfoCommand.func1(0xc000176dc0, 0xc000092720, 0x0, 0x2, 0x0, 0x0)
azure-arm: 	/go/src/github.com/docker/cli/cli/command/system/info.go:54 +0x4d
azure-arm: github.com/docker/cli/vendor/github.com/spf13/cobra.(*Command).execute(0xc000176dc0, 0xc00030bc90, 0x2, 0x2, 0xc000176dc0, 0xc00030bc90)
azure-arm: 	/go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:850 +0x472
azure-arm: github.com/docker/cli/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc000478840, 0xc00030bc80, 0x3, 0x3)
azure-arm: 	/go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:958 +0x375
azure-arm: github.com/docker/cli/vendor/github.com/spf13/cobra.(*Command).Execute(...)
azure-arm: 	/go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:895
azure-arm: main.runDocker(0xc000107110, 0x27205e0, 0xc000006020)
azure-arm: 	/go/src/github.com/docker/cli/cmd/docker/docker.go:287 +0x1eb
azure-arm: main.main()
azure-arm: 	/go/src/github.com/docker/cli/cmd/docker/docker.go:298 +0xfe
azure-arm: Exception: Failed to switch Docker daemon. Exit Code: 1

Expected behavior:
Successfully switch to windows docker daemon.

Thank you!