You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+73-3Lines changed: 73 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,7 @@ Please note that you *do not* need the ```""``` or ```''``` characters for a str
60
60
61
61
### Caution
62
62
63
-
You *should not* share this ```.env``` file to your peers or commit/push it to the version control. You should add the file to the ```.gitignore``` file to avoid adding it to a version control or public repo accidentally.
63
+
You *should not* share this ```.env``` file to your peers or commit/push it to the version control. You should add the file to the ```.gitignore``` file to avoid adding it to a version control or public repository accidentally.
64
64
65
65
You can create a ```.env.example``` file as a template for environment variables and ```.env``` file sharing. The file has the same parameters' keys as a ```.env``` file but without sensitive values as the following example:
Next, the application uses those configurations to authenticate with RDP Auth Service, get the RTO WebSocket endpoint dynamically from the Service Discovery mechanism and further connects and consume the real-time streaming data from the WebSocket server.
289
289
290
+
## dotenv with Docker
291
+
292
+
[Docker](https://www.docker.com/) supports the environment variables usage in the [Dockerfile](https://docs.docker.com/engine/reference/builder/#env), [docker run command](https://docs.docker.com/engine/reference/commandline/run/) and [Docker compose](https://docs.docker.com/compose/environment-variables/).
293
+
294
+
### dotenv with Dockerfile
295
+
296
+
#### Dockerfile ENV instruction
297
+
298
+
Let's demonstrate with the Dockerfile first. You can use the ```ENV``` instruction to set the environment variable in the image.
299
+
300
+
```
301
+
ENV <key>=<value> ...
302
+
```
303
+
You can set multiple environment variables in a single ```ENV``` instruction as well.
304
+
305
+
```
306
+
ENV <key>=<value> \
307
+
<key>=<value> \
308
+
<key>=<value>
309
+
```
310
+
311
+
The Dockerfile below set both application and System's configurations in the Dockerfile.
312
+
313
+
```
314
+
# Update PATH environment variable + set Python buffer to make Docker print every messages instantly.
315
+
ENV PATH=/root/.local:$PATH \
316
+
USERNAME=DOCKER_CONTAINER \
317
+
PYTHONUNBUFFERED=1
318
+
```
319
+
All containers from the result image can access the environment variables set using Dockerfile ```ENV``` instruction, unless it is replaced by the Docker run command options.
320
+
321
+
When you run the Docker containers from the above Docker image setting, the ```System.out.println(dotenv.get("USERNAME"));``` (Java) and ``` print('User: ', os.getenv('USERNAME'))``` (Python) will print the USERNAME information as *DOCKER_CONTAINER*.
322
+
323
+
#### Docker Run command
324
+
325
+
You can use the ```--env``` (```-e``` for shorter syntax) options with the Docker run command to set the environment variable of the container.
326
+
327
+
```
328
+
$> docker run --env <key>=<value> IMAGE
329
+
```
330
+
331
+
Please note that if you want to set multiple environment variables, you need to set ```--env```` multiple times
0 commit comments