I put the docker in swarm mode and did the following
echo "'admin'" | docker secret create password -
docker service create \
--network="host" \
--secret source=password,target=password \
-e PASSWORD='/run/secrets/password' \
<image>
I was not able to pass the password secret created via environment variable through docker service.
Please help me out where I am going wrong.
You are misunderstanding the concept of docker secrets. The whole point of creating secrets is avoiding putting sensitive information into environment variables.
In your example the
PASSWORD
environment variable will simply carry the value/run/secrets/password
which is a file name and not the passwordadmin
.A valid usecase of docker secrets would be, that your docker-image reads the password from that file. Checkout the docs here especially the example about MySQL:
In short: your docker image should read the content of the file
/run/secrets/password