docker_practice/swarm_mode/secret.md

86 lines
3.2 KiB
Go
Raw Permalink Normal View History

# Swarm
2017-12-06 13:23:22 +08:00
`密码``证书` volume
Docker `secrets` Swarm Docker 访
2017-12-20 23:44:38 +08:00
> `secret` `Docker Compose` 使
2017-12-06 13:23:22 +08:00
`docker secret` Swarm 使
Swarm `mysql` `wordpress`
## secret
2017-12-06 13:23:22 +08:00
使 `docker secret create` `secret`
```bash
$ openssl rand -base64 20 | docker secret create mysql_password -
$ openssl rand -base64 20 | docker secret create mysql_root_password -
```
## secret
2017-12-06 13:23:22 +08:00
使 `docker secret ls` `secret`
```bash
$ docker secret ls
ID NAME CREATED UPDATED
l1vinzevzhj4goakjap5ya409 mysql_password 41 seconds ago 41 seconds ago
yvsczlx9votfw3l0nz5rlidig mysql_root_password 12 seconds ago 12 seconds ago
```
## MySQL
2017-12-06 13:23:22 +08:00
```bash
$ docker network create -d overlay mysql_private
$ docker service create \
--name mysql \
--replicas 1 \
--network mysql_private \
--mount type=volume,source=mydata,destination=/var/lib/mysql \
--secret source=mysql_root_password,target=mysql_root_password \
--secret source=mysql_password,target=mysql_password \
-e MYSQL_ROOT_PASSWORD_FILE="/run/secrets/mysql_root_password" \
-e MYSQL_PASSWORD_FILE="/run/secrets/mysql_password" \
-e MYSQL_USER="wordpress" \
-e MYSQL_DATABASE="wordpress" \
mysql:latest
```
`target` `secret` `tmpfs` `/run/secrets`
```bash
$ docker service create \
--name wordpress \
--replicas 1 \
--network mysql_private \
--publish target=30000,port=80 \
--mount type=volume,source=wpdata,destination=/var/www/html \
--secret source=mysql_password,target=wp_db_password,mode=0444 \
2017-12-06 13:23:22 +08:00
-e WORDPRESS_DB_USER="wordpress" \
-e WORDPRESS_DB_PASSWORD_FILE="/run/secrets/wp_db_password" \
-e WORDPRESS_DB_HOST="mysql:3306" \
-e WORDPRESS_DB_NAME="wordpress" \
wordpress:latest
```
```bash
$ docker service ls
ID NAME MODE REPLICAS IMAGE
wvnh0siktqr3 mysql replicated 1/1 mysql:latest
nzt5xzae4n62 wordpress replicated 1/1 wordpress:latest
```
访 `IP:30000` `WordPress` 使
MySQL `docker secret`