There are some questions about using secrets with docker-compose
without swarm mode, but when trying to follow some of them, I never managed to read the secrets inside running container.
Approach #1
docker-compose.yml
:
version: "3.8"
services:
server:
image: alpine:latest
secrets:
- sec-str
environment:
- TE_STR=${sec-str}
command: tail -F .
secrets:
sec-str:
file: ./secret.s
secret.s
:
sec-str="A!Bit@complicated-String^%"
Outcome:
/ # echo $TE_STR
str
Approach #2
Only change is made here, in secret.s
:
"A!Bit@complicated-String^%"
Outcome:
/ # echo $TE_STR
str
Approach #3
TE_STR=${sec-str}
replaced with TE_STR=$sec-str
.
Outcome:
/ # echo $TE_STR
-str
Running out of ideas for now. Any clues from you?
Secrets are still files inside the container. You can find yours at:
If you need it as en environment variable do as follows:
This will set TE_STR to the contents of your secret.