Skip to content

Windows: missing secrets file creates file-named directory #8305

@philliphoff

Description

@philliphoff

Description of the issue

On Windows, when starting a composition that refers to a secret file which does not exist, an "invalid mount config for type" error is generated and a directory with the same name as the file is created.

This behavior is not seen on Mac, with the same version of Docker Desktop and Docker Compose.

This may be related to #5377 but seems only to affect Windows.

Context information (for bug reports)

Output of docker-compose version

docker-compose version 1.29.0, build 07737305
docker-py version: 5.0.0
CPython version: 3.9.0
OpenSSL version: OpenSSL 1.1.1g  21 Apr 2020

Output of docker version

Client: Docker Engine - Community
 Cloud integration: 1.0.12
 Version:           20.10.5
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        55c4c88
 Built:             Tue Mar  2 20:14:53 2021
 OS/Arch:           windows/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.5
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       363e9a8
  Built:            Tue Mar  2 20:15:47 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.4
  GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e
 runc:
  Version:          1.0.0-rc93
  GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Output of docker-compose config
(Make sure to add the relevant -f and other flags)

D:\Repos\Scratch\compose-test>docker-compose config
secrets:
  postgres_db:
    file: D:\Repos\Scratch\compose-test\postgres_db.txt
  postgres_password:
    file: D:\Repos\Scratch\compose-test\postgres_password.txt
  postgres_user:
    file: D:\Repos\Scratch\compose-test\postgres_user.txt
services:
  db:
    environment:
      POSTGRES_DB_FILE: /run/secrets/postgres_db
      POSTGRES_INITDB_ARGS: --auth=md5
      POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
      POSTGRES_USER_FILE: /run/secrets/postgres_user
    healthcheck:
      interval: 10s
      retries: 5
      test:
      - CMD-SHELL
      - pg_isready -U postgres
      timeout: 5s
    image: postgres:latest
    labels:
      com.microsoft.vscode.dev-container-name: webapi-nodejs-dev-container
    restart: unless-stopped
    secrets:
    - source: postgres_db
    - source: postgres_password
    - source: postgres_user
    volumes:
    - postgres-data:/var/lib/postgresql/data:rw
version: '3.7'
volumes:
  postgres-data: {}

Steps to reproduce the issue

  1. Add the following to docker-compose.yml in an otherwise empty directory:
version: '3.7'

secrets:
  postgres_db:
    file: postgres_db.txt
  postgres_password:
    file: postgres_password.txt
  postgres_user:
    file: postgres_user.txt

services:
  db:
    image: postgres:latest
    restart: unless-stopped
    volumes:
      - postgres-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB_FILE=/run/secrets/postgres_db
      - POSTGRES_INITDB_ARGS=--auth=md5
      - POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
      - POSTGRES_USER_FILE=/run/secrets/postgres_user
    labels:
      com.microsoft.vscode.dev-container-name: webapi-nodejs-dev-container
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 5s
      retries: 5
    secrets:
      - postgres_db
      - postgres_password
      - postgres_user

    # Add "forwardPorts": ["5432"] to **devcontainer.json** to forward Postgress locally.
    # (Adding the "ports" property to this file will not forward from a Codespace.)

volumes:
  postgres-data:
  1. docker-compose up --remove-orphans

Observed result

  1. Composition fails to start (which is expected).
  2. Folders are created in the directory with the same names as the declared secrets file (not expected).

NOTE: This does not repro on every attempt. What I observe is that it works on the first attempt, but not (always) subsequent attempts. However, if you tweak the names of the secrets files, then you can (usually) repro it on the next attempt.

Expected result

  1. Composition fails to start.
  2. No directories (or files) created.

Stacktrace / full error message

D:\Repos\Scratch\compose-test>docker-compose up --remove-orphans
WARNING: Service "db" uses an undefined secret file "D:\Repos\Scratch\compose-test\postgres_db.txt", the following file should be created "D:\Repos\Scratch\compose-test\postgres_db.txt"
WARNING: Service "db" uses an undefined secret file "D:\Repos\Scratch\compose-test\postgres_password.txt", the 
following file should be created "D:\Repos\Scratch\compose-test\postgres_password.txt"
WARNING: Service "db" uses an undefined secret file "D:\Repos\Scratch\compose-test\postgres_user.txt", the following file should be created "D:\Repos\Scratch\compose-test\postgres_user.txt"
Docker Compose is now in the Docker CLI, try `docker compose up`

Removing orphan container "compose-test_app_1"
Starting compose-test_db_1 ... error

ERROR: for compose-test_db_1  Cannot start service db: invalid mount config for type "bind": bind source path does not exist: /run/desktop/mnt/host/d/Repos/Scratch/compose-test/postgres_db.txt

ERROR: for db  Cannot start service db: invalid mount config for type "bind": bind source path does not exist: 
/run/desktop/mnt/host/d/Repos/Scratch/compose-test/postgres_db.txt
ERROR: Encountered errors while bringing up the project.

Additional information

OS version / distribution, docker-compose install method, etc.

Windows 10 (Version 21H1, OS Build 19043.964)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions