Difference between revisions of "Docker Secret"
Jump to navigation
Jump to search
(Created page with "Docker secret is a way to specify parameters without showing its plain text value in Dockerfile.") |
|||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Docker secret is a way to specify parameters without showing its plain text value in Dockerfile. | Docker secret is a way to specify parameters without showing its plain text value in Dockerfile. One of the obvious starting point is the official Docker documentation website<ref>https://docs.docker.com/engine/swarm/secrets/</ref>. | ||
=Use Secret in Docker Compose= | |||
The following docker-compose file is an example. | |||
<syntaxhighlight lang="ruby" line> | |||
version: "3.9" | |||
services: | |||
db: | |||
image: mysql:latest | |||
volumes: | |||
- db_data:/var/lib/mysql | |||
environment: | |||
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db_root_password | |||
MYSQL_DATABASE: wordpress | |||
MYSQL_USER: wordpress | |||
MYSQL_PASSWORD_FILE: /run/secrets/db_password | |||
secrets: | |||
- db_root_password | |||
- db_password | |||
wordpress: | |||
depends_on: | |||
- db | |||
image: wordpress:latest | |||
ports: | |||
- "8000:80" | |||
environment: | |||
WORDPRESS_DB_HOST: db:3306 | |||
WORDPRESS_DB_USER: wordpress | |||
WORDPRESS_DB_PASSWORD_FILE: /run/secrets/db_password | |||
secrets: | |||
- db_password | |||
secrets: | |||
db_password: | |||
file: db_password.txt | |||
db_root_password: | |||
file: db_root_password.txt | |||
volumes: | |||
db_data: | |||
</syntaxhighlight> | |||
=References= |
Latest revision as of 13:14, 29 June 2021
Docker secret is a way to specify parameters without showing its plain text value in Dockerfile. One of the obvious starting point is the official Docker documentation website[1].
Use Secret in Docker Compose
The following docker-compose file is an example.
version: "3.9"
services:
db:
image: mysql:latest
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db_root_password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD_FILE: /run/secrets/db_password
secrets:
- db_root_password
- db_password
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD_FILE: /run/secrets/db_password
secrets:
- db_password
secrets:
db_password:
file: db_password.txt
db_root_password:
file: db_root_password.txt
volumes:
db_data: