File tree 3 files changed +30
-8
lines changed
3 files changed +30
-8
lines changed Original file line number Diff line number Diff line change 154
154
.yarn /build-state.yml
155
155
.yarn /install-state.gz
156
156
.pnp. *
157
- . /app /node_modules
157
+ . /app /node_modules
158
+ .env
Original file line number Diff line number Diff line change @@ -144,3 +144,24 @@ mkdir app
144
144
mongodb :
145
145
condition : service_healthy
146
146
` ` `
147
+
148
+ ## for security issue: set those secret with environment variable
149
+
150
+ 1. use environment to inject credential data
151
+ ` ` ` yaml
152
+ environment :
153
+ MONGO_INITDB_ROOT_USERNAME : ${MONGO_DB_ADMIN_USER}
154
+ MONGO_INITDB_ROOT_PASSWORD : ${MONGO_DB_ADMIN_PASSWD}
155
+ ` ` `
156
+
157
+ ## use docker compose secret to inject secret
158
+ ` ` ` yaml
159
+ services :
160
+ myapp :
161
+ image : maapp:latest
162
+ secrets :
163
+ - my_secret
164
+ secrets :
165
+ my_secret :
166
+ file : ./my_secret.txt
167
+ ` ` `
Original file line number Diff line number Diff line change @@ -7,23 +7,23 @@ services:
7
7
image : mongo:latest
8
8
container_name : mongodb
9
9
environment :
10
- MONGO_INITDB_ROOT_USERNAME : admin
11
- MONGO_INITDB_ROOT_PASSWORD : supersecret
10
+ MONGO_INITDB_ROOT_USERNAME : ${MONGO_DB_ADMIN_USER}
11
+ MONGO_INITDB_ROOT_PASSWORD : ${MONGO_DB_ADMIN_PASSWD}
12
12
networks :
13
13
- mongo-network
14
14
ports :
15
15
- 27017:27017
16
16
healthcheck :
17
- test : echo 'db.runCommand("ping").ok' | mongosh mongodb://admin:supersecret @localhost:27017/ --quiet
17
+ test : echo 'db.runCommand("ping").ok' | mongosh mongodb://${MONGO_DB_ADMIN_USER}:${MONGO_DB_ADMIN_PASSWD} @localhost:27017/ --quiet
18
18
interval : 5s
19
19
timeout : 10s
20
20
retries : 3
21
21
mongo-express :
22
22
image : mongo-express:latest
23
23
container_name : mongo-express
24
24
environment :
25
- ME_CONFIG_MONGODB_ADMINUSERNAME : admin
26
- ME_CONFIG_MONGODB_ADMINPASSWORD : supersecret
25
+ ME_CONFIG_MONGODB_ADMINUSERNAME : ${MONGO_DB_ADMIN_USER}
26
+ ME_CONFIG_MONGODB_ADMINPASSWORD : ${MONGO_DB_ADMIN_PASSWD}
27
27
ME_CONFIG_MONGODB_SERVER : mongodb
28
28
depends_on :
29
29
mongodb :
@@ -42,8 +42,8 @@ services:
42
42
networks :
43
43
- mongo-network
44
44
environment :
45
- MONGO_DB_USERNAME : admin
46
- MONGO_DB_PWD : supersecret
45
+ MONGO_DB_USERNAME : ${MONGO_DB_ADMIN_USER}
46
+ MONGO_DB_PWD : ${MONGO_DB_ADMIN_PASSWD}
47
47
ports :
48
48
- 3000:3000
49
49
depends_on :
You can’t perform that action at this time.
0 commit comments