Skip to content

Instantly share code, notes, and snippets.

@ronaldb
Last active April 7, 2024 04:29
Show Gist options
  • Save ronaldb/d4b3d3327a5f80bfd12d748ca0ae91ae to your computer and use it in GitHub Desktop.
Save ronaldb/d4b3d3327a5f80bfd12d748ca0ae91ae to your computer and use it in GitHub Desktop.
Docker - Use secrets in a single node docker environment and mysql
version: "3.6"
services:
my_sql:
image: mysql:5.7
volumes:
- ./data:/var/lib/mysql
secrets:
- my_secret
environment:
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/my_secret
MYSQL_DATABASE: todos
nodejs:
image: node:8
secrets:
- my_secret
environment:
MYSQL_PASSWORD_FILE: /run/secrets/my_secret
secrets:
my_secret:
file: ./super_duper_secret.txt
const fs = require('fs');
passwd = fs.readFileSync(process.env.MYSQL_PASSWORD_FILE, 'utf8').trim();
console.log(passwd);
@barkhachoithani
Copy link

I'm getting below error while building.

ERROR: for secrets-poc_my_sql_1 Cannot create container for service my_sql: invalid mount config for type "bind": stat /home/user1/secrets-poc/super_duper_secret.txt: permission denied

ERROR: for my_sql Cannot create container for service my_sql: invalid mount config for type "bind": stat /home/user1/secrets-poc/super_duper_secret.txt: permission denied
ERROR: Encountered errors while bringing up the project.
Anything I am missing here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment