Solved: Cannot create container for service traefik: invalid volume specification: '/var/run/docker.sock: /var/run/docker.sock:ro'

I've been exploring Docker containers and using Traefik as a reverse proxy. I was trying to get the Docker example from https://docs.traefik.io/user-guides/docker-compose/basic-example/ to work with Windows Containers. When I tried to start the containers with the example, Docker returned the following error:

ERROR: for traefik Cannot create container for service traefik: invalid volume specification: '/var/run/docker.sock:/var/run/docker.sock:ro'

I spent some time searching for a solution to the issue and finally found out that the cause of this is that the example is set up for Linux and doesn't work in Windows containers. In Windows, Docker exposes its API via named pipes.

Below is an updated Docker Compose file which works on Windows.

version: "3.3"

services:

  traefik:
    image: "traefik:windowsservercore-1809"
    container\_name: "traefik"
    command:
      - "--log.level=DEBUG"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - source: '\\\\.\\pipe\\docker\_engine'
        target: '\\\\.\\pipe\\docker\_engine'
        type: npipe
  whoami:
    image: "containous/whoami"
    container\_name: "simple-service"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.whoami.rule=Host(\`whoami.localhost\`)"
      - "traefik.http.routers.whoami.entrypoints=web"

Published in: Troubleshooting