sixeyed / docker-on-windows

Code samples for the book "Docker on Windows"
https://www.amazon.com/gp/product/1789617375/
Apache License 2.0
228 stars 125 forks source link

ch05 reverse-proxy has problems #17

Open khtan opened 3 years ago

khtan commented 3 years ago

Hello,

Thank you for an excellent book. I have been reading and following through your examples and through the standardization that Docker provides, the examples still run as expected.

However, in Ch5, when I run ch05-run-nerd-dinner_part-2.ps1 ( after part-1 ), I noticed that while the reverse-proxy service does run, the transcript indicates some errors. Log: 1 > time="2021-01-16T18:11:08-08:00" level=error msg="Failed to retrieve information of the docker client and server host: error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/version: open //./pipe/docker_engine: message readmode pipes not supported In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running." 2 > time="2021-01-16T18:11:08-08:00" level=error msg="Provider connection error Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/version: open //./pipe/docker_engine: message readmode pipes not supported In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.

github.com/containous/traefik/vendor/github.com/docker/docker/client.(Client).doRequest /go/src/github.com/containous/traefik/vendor/github.com/docker/docker/client/request.go:182 github.com/containous/traefik/vendor/github.com/docker/docker/client.(Client).sendRequest /go/src/github.com/containous/traefik/vendor/github.com/docker/docker/client/request.go:122 github.com/containous/traefik/vendor/github.com/docker/docker/client.(Client).get /go/src/github.com/containous/traefik/vendor/github.com/docker/docker/client/request.go:37 github.com/containous/traefik/vendor/github.com/docker/docker/client.(Client).ServerVersion /go/src/github.com/containous/traefik/vendor/github.com/docker/docker/client/version.go:12 github.com/containous/traefik/provider/docker.(Provider).Provide.func1.1 /go/src/github.com/containous/traefik/provider/docker/docker.go:137 github.com/containous/traefik/safe.OperationWithRecover.func1 /go/src/github.com/containous/traefik/safe/routine.go:160 github.com/containous/traefik/vendor/github.com/cenk/backoff.RetryNotify /go/src/github.com/containous/traefik/vendor/github.com/cenk/backoff/retry.go:37 github.com/containous/traefik/provider/docker.(Provider).Provide.func1 /go/src/github.com/containous/traefik/provider/docker/docker.go:252 github.com/containous/traefik/safe.(Pool).GoCtx.func1 /go/src/github.com/containous/traefik/safe/routine.go:62 github.com/containous/traefik/safe.GoWithRecover.func1 /go/src/github.com/containous/traefik/safe/routine.go:142 runtime.goexit /usr/local/go/src/runtime/asm_amd64.s:1333 error during connect github.com/containous/traefik/vendor/github.com/docker/docker/client.(Client).doRequest /go/src/github.com/containous/traefik/vendor/github.com/docker/docker/client/request.go:185 github.com/containous/traefik/vendor/github.com/docker/docker/client.(Client).sendRequest /go/src/github.com/containous/traefik/vendor/github.com/docker/docker/client/request.go:122 github.com/containous/traefik/vendor/github.com/docker/docker/client.(Client).get /go/src/github.com/containous/traefik/vendor/github.com/docker/docker/client/request.go:37 github.com/containous/traefik/vendor/github.com/docker/docker/client.(Client).ServerVersion /go/src/github.com/containous/traefik/vendor/github.com/docker/docker/client/version.go:12 github.com/containous/traefik/provider/docker.(Provider).Provide.func1.1 /go/src/github.com/containous/traefik/provider/docker/docker.go:137 github.com/containous/traefik/safe.OperationWithRecover.func1 /go/src/github.com/containous/traefik/safe/routine.go:160 github.com/containous/traefik/vendor/github.com/cenk/backoff.RetryNotify /go/src/github.com/containous/traefik/vendor/github.com/cenk/backoff/retry.go:37 github.com/containous/traefik/provider/docker.(Provider).Provide.func1 /go/src/github.com/containous/traefik/provider/docker/docker.go:252 github.com/containous/traefik/safe.(Pool).GoCtx.func1 /go/src/github.com/containous/traefik/safe/routine.go:62 github.com/containous/traefik/safe.GoWithRecover.func1 /go/src/github.com/containous/traefik/safe/routine.go:142 runtime.goexit /usr/local/go/src/runtime/asm_amd64.s:1333, retrying in 369.950822ms"

Here is my Docker host environment : Powershell : run as an Administrator, with ExecutionPolicy = RemoteSigned, All. PC: Windows 10, 2004 Docker Desktop: 3.0.4 Docker Engine: 20.10.2

Tried the following :

  1. Added --isolation hyperv option to Docker run did not work Based on https://github.com/StefanScherer/dockerfiles-windows/issues/383

2.Substitute sixeyed/traefik:v1.7.8-windowsservercore-ltsc2019 for a newer Traefix traefik:v2.3.7-windowsservercore-1809 failed with error :

2021/01/16 21:13:12 command traefik error: failed to decode configuration from flags: field not found, node: docker This tells me that I should look at the Dockerfile for sixeyed/traefik:v1.7.8-windowsservercore-ltsc2019 to find out how the --docker flag should be handled.

Unfortunately sixeyed/traefik is a container, not an image and does not have the Dockerfile available for inspection.

Hopefully, you can provide some guidance to get your example working again.

Thanks,

cb-hamilton commented 2 years ago

I encountered this issue and resolved it by creating a new traefik docker image based on the ltsc2022 Windows Server Core base OS image.

Docker Environment docker -version:

Client:
 Cloud integration: v1.0.20
 Version:           20.10.10
 API version:       1.41
 Go version:        go1.16.9
 Git commit:        b485636
 Built:             Mon Oct 25 07:47:53 2021
 OS/Arch:           windows/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.10
  API version:      1.41 (minimum version 1.24)
  Go version:       go1.16.9
  Git commit:       e2f740d
  Built:            Mon Oct 25 07:43:13 2021
  OS/Arch:          windows/amd64
  Experimental:     false

Host Environment ver:

Microsoft Windows [Version 10.0.22000.1098]

Steps to setup reverse proxy:

  1. Create the Dockerfile below that contains the updated base OS image, mcr.microsoft.com/windows/servercore:ltsc2022 . Unmodified Dockerfile was retrieved from here.
FROM mcr.microsoft.com/windows/servercore:ltsc2022

COPY --from=traefik:v1.7.8-nanoserver-sac2016 /traefik.exe /traefik.exe

EXPOSE 80
ENTRYPOINT ["/traefik"]

# Metadata (copied from official Traefik image)
LABEL org.label-schema.vendor="Containous" \
      org.label-schema.url="https://traefik.io" \
      org.label-schema.name="Traefik" \
      org.label-schema.description="A modern reverse-proxy" \
      org.label-schema.version="v1.7.8" \
      org.label-schema.docker.schema-version="1.0"
  1. Build the image using the directory containing the Dockerfile as the context for the build.

docker build . -t ch05-nerd-dinner-reverse-proxy:2e

  1. Run the container using the new image and the --isolation=process flag.
docker container run -d -p 80:80 -p 8080:8080 `
  --name reverse-proxy `
  -v \\.\pipe\docker_engine:\\.\pipe\docker_engine `
  --isolation=process `
  ch05-nerd-dinner-reverse-proxy:2e `
  --api --docker --docker.endpoint=npipe:////./pipe/docker_engine --logLevel=DEBUG