# How to access Docker Secrets in Node-RED Container

**URL:** https://discourse.nodered.org/t/how-to-access-docker-secrets-in-node-red-container/66330
**Category:** General
**Tags:** docker
**Created:** [11 August 2022 13:09 UTC](https://discourse.nodered.org/t/how-to-access-docker-secrets-in-node-red-container/66330 "2022-08-11T13:09:46Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![kitkat159](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kitkat159/32/66066_2.png) [@kitkat159](https://discourse.nodered.org/u/kitkat159)
#### Post date: [11 August 2022 13:09 UTC](https://discourse.nodered.org/t/how-to-access-docker-secrets-in-node-red-container/66330/1 "2022-08-11T13:09:46Z")

</div>

Hey everyone!  
I am running Node-RED under Docker and for development I am setting some credentials for an external server as environment variables. However, in production use I want to set these credentials Docker Secrets, but I don't know how to access them inside the container.

Is anyone experienced with this topic? Or maybe there's a better way to hide credentials?

Thank you all in advance and have a great day!

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [11 August 2022 13:40 UTC](https://discourse.nodered.org/t/how-to-access-docker-secrets-in-node-red-container/66330/2 "2022-08-11T13:40:27Z")

</div>

> [@kitkat159](#):
>
> Docker Secrets

Docker uses an in-memory filesystem for storing secrets. The secrets are standard files inside the container in `/run/secrets/`. So you should be able to use the file reader node in a flow.

---

<div class="post-metadata">

### Author: ![kitkat159](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kitkat159/32/66066_2.png) [@kitkat159](https://discourse.nodered.org/u/kitkat159)
#### Post date: [12 August 2022 06:04 UTC](https://discourse.nodered.org/t/how-to-access-docker-secrets-in-node-red-container/66330/3 "2022-08-12T06:04:38Z")

</div>

Thank you! I think I've read this before but I wasn't able to integrate this in my project. But now it works 🙂

---

<div class="post-metadata">

### Author: ![kitkat159](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kitkat159/32/66066_2.png) [@kitkat159](https://discourse.nodered.org/u/kitkat159)
#### Post date: [17 August 2022 08:49 UTC](https://discourse.nodered.org/t/how-to-access-docker-secrets-in-node-red-container/66330/4 "2022-08-17T08:49:22Z")

</div>

So I revisited my project and I can now access the Docker secrets. However, I replaced the environment variables with the Docker secrets and now I have to change my function node.  
Currently it is looking like this:

```auto
msg.payload = `
	<body>
		<request>
			<name>${env.get('LOGIN_NAME')}</name>
			<password>${env.get('LOGIN_PASSWORD')}</password>
			<input>
				<in_json>${msg.payload}</in_json>
			</input>
		</request>
	</body>
`;
return msg;

```

Is there a way to replace the `env.get(...)` with Docker secrets?

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [17 August 2022 09:59 UTC](https://discourse.nodered.org/t/how-to-access-docker-secrets-in-node-red-container/66330/5 "2022-08-17T09:59:00Z")

</div>

You could load them into either env variables or global vars in your settings.js file.

---

<div class="post-metadata">

### Author: ![kitkat159](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kitkat159/32/66066_2.png) [@kitkat159](https://discourse.nodered.org/u/kitkat159)
#### Post date: [18 August 2022 07:43 UTC](https://discourse.nodered.org/t/how-to-access-docker-secrets-in-node-red-container/66330/6 "2022-08-18T07:43:10Z")

</div>

Hmmm... sounds like a step backwards. Do you think it is reasonable to use Docker secrets instead of using the `-e`-flag and then loading the secrets as env variables? Would that be more secure than just passing them into the container as env variables?

And if so, how would you load them as env variables?

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [18 August 2022 08:57 UTC](https://discourse.nodered.org/t/how-to-access-docker-secrets-in-node-red-container/66330/7 "2022-08-18T08:57:59Z")

</div>

I don't use docker all that much so I'm not an expert. However, I would say yes, I think that is more secure since they will not be visible outside the container.

If you wanted more than that, I would likely recommend setting up a small, standalone node.js service within the container that consumed the secrets and exposed an API that node-red could access. Putting that in a separate container could allow another step up in security by limiting access between the containers. Node-RED itself can be an API service of course and running two node-red containers, one with just the secure stuff in and the other for general use would be a valid approach. But of course all of that requires more device resources.

---

<div class="post-metadata">

### Author: ![kitkat159](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kitkat159/32/66066_2.png) [@kitkat159](https://discourse.nodered.org/u/kitkat159)
#### Post date: [18 August 2022 09:15 UTC](https://discourse.nodered.org/t/how-to-access-docker-secrets-in-node-red-container/66330/8 "2022-08-18T09:15:28Z")

</div>

Okay, thank you 🙂 I will try and research more on that and if I find a solution that works for me, I will update

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [1 September 2022 09:15 UTC](https://discourse.nodered.org/t/how-to-access-docker-secrets-in-node-red-container/66330/9 "2022-09-01T09:15:39Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
