Docker-compose toolbox secrets files not mounting properly
Asked Answered
W

2

18

I am trying to compose a stack using secrets for development, i use local files in docker/secrets/FILE_NAME I had this working in windows 10, but I'm struggling to get it to work under win7 toolbox. I get an error:

Cannot create container for service db: 
invalid volume specification:
 'C:\project\docker\secrets\DB_USERNAME:/run/secrets/db-username:ro'

I was trying to set COMPOSE_CONVERT_WINDOWS_PATH but unfortunately, this does not change anything. I will get the same output with true or false. Setting absolute paths did not help either.

Docker compose version 1.16.1 build 6d1ac219 Docker version 17.10.0-ce, build f4ffd25

My docker-compose.yml

version: '3.3'

services:
  db:
    image: postgres
    volumes:
      - db-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_PASSWORD_FILE=/run/secrets/db-password
      - POSTGRES_USER_FILE=/run/secrets/db-username
      - POSTGRES_DB_FILE=/run/secrets/db-name
    secrets:
      - db-username
      - db-password
      - db-name
  web:
    build: 
      context: ./docker/machines/django/
      args:
        buildno: 1
    command: python3 manage.py runserver 0.0.0.0:8000
    volumes:
      - ./Server:/Server
    ports:
      - "8000:8000"
    depends_on:
      - db
    secrets:
      - db-username
      - db-password
      - db-name

secrets:
  db-username:
    file: ./docker/secrets/DB_USERNAME
  db-password:
    file: ./docker/secrets/DB_PASSWORD
  db-name:
    file: ./docker/secrets/DB_NAME

volumes:
  db-data:
    driver: "local"
Weitman answered 16/11, 2017 at 9:39 Comment(0)
T
1

it is likely to due to difference in how Windows 7 and Windows 10 handle file paths. Docker Toolbox, which is used for older Windows systems that do not support Docker Desktop (like Windows 7), runs in a VirtualBox VM and has different path requirements.

In Docker Toolbox, project should be located in the C:\Users directory. This is because Docker Toolbox can only mount file paths from the C:\Users directory. So, if your project is located outside of this directory, Docker Toolbox won’t be able to find the files.

you can move your project to C:\Users and update the paths in docker-compose.yml file to reflect the new location.

For example, if your username is myuser and you moved your project to a folder named myproject in the C:\Users directory, the paths would look like this:

secrets:
  db-username:
    file: /c/Users/myuser/myproject/docker/secrets/DB_USERNAME
  db-password:
    file: /c/Users/myuser/myproject/docker/secrets/DB_PASSWORD
  db-name:
    file: /c/Users/myuser/myproject/docker/secrets/DB_NAME
Talishatalisman answered 2/2 at 17:58 Comment(0)
T
0

it seems be a windows permission issue ? check the file permissions

Thursby answered 6/11, 2023 at 12:48 Comment(1)
Could you please edit this according to How to Answer? Why do you think it to be a permission issue and what should one look for in the file permissions?Pacify

© 2022 - 2024 — McMap. All rights reserved.