简体   繁体   中英

Secrets in docker-compose mounting as empty directories

I've been trying to add secrets to my docker container using docker-compose secrets without any luck.

Using this docker-compose.yml the secret is mounted under /run/secrets/my_secret as an empty directory, not as a file:

version: '3.7'

services:
  main:
    build:
      context: ./
    secrets:
      - my_secret

secrets:
  my_secret:
    file: first_secret.txt

I have tried to explicitly define the target and source

main:
  ...
  secrets:
        - source: my_secret
          target: /usr/local/secrets/custom_location

but it still gets added as an empty directory, why is that?

I'm aware of the limitations of using secrets in docker-compose without docker swarm and simply want to use secrets as a semantic way to define secrets.

Apparently the ability to use secrets in docker-compose is still a work in progress (thus, doesn't work). But you may be able to use a workaround using a Dockerfile.

There's an in depth tutorial about how to do this here: https://pythonspeed.com/articles/build-secrets-docker-compose/

Remove the container ( docker container rm … ), then run docker compose up again.

Source: https://github.com/docker/compose/issues/4865#issuecomment-468644938 (worked for me).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM