patterndockerMinor
Secrets in Docker without Swarm
Viewed 0 times
dockerswarmsecretswithout
Problem
I am using Docker, but not Swarm (or any other orchestration) for a project.
Is there a way to leverage Docker Secrets without Swarm?
Is there a way to leverage Docker Secrets without Swarm?
Solution
You can use docker secrets a bit differently using
Example:
It's similar to how you define volumes and networks in a compose file.
Keep in mind that this isn't true secret implementation. Here's the github PR that added this feature, along with the main file if you're interested.
docker-compose without having to use swarm. See this for the official documentation.Example:
- Create a simple compose file like so,
version: "3.7"
services:
db:
image: mariadb:10.5.2
env_file:
- ./db.env
secrets:
- rootpass
- dbpass
- mysqldb
- mysqluser
restart: always- Now add the following in the end
secrets:
rootpass:
file: /tmp/root_pass
dbpass:
file: /tmp/db_pass
mysqldb:
file: /tmp/mysql_db
mysqluser:
file: /tmp/mysql_user- Inside those files, keep your password, username, database name etc. in plain text. Then simply deploy the containers
docker-compose up -d.
It's similar to how you define volumes and networks in a compose file.
Keep in mind that this isn't true secret implementation. Here's the github PR that added this feature, along with the main file if you're interested.
Code Snippets
version: "3.7"
services:
db:
image: mariadb:10.5.2
env_file:
- ./db.env
secrets:
- rootpass
- dbpass
- mysqldb
- mysqluser
restart: alwayssecrets:
rootpass:
file: /tmp/root_pass
dbpass:
file: /tmp/db_pass
mysqldb:
file: /tmp/mysql_db
mysqluser:
file: /tmp/mysql_userContext
StackExchange DevOps Q#12101, answer score: 3
Revisions (0)
No revisions yet.