IMD SolutionComputing LibraryShop main store

Troubleshooting

Node-RED Docker EACCES mkdir: write to host storage, not container

Edge computing and IIoT Published 7 min read

Short answer

The EACCES mkdir error means the file node is creating a directory inside the container's filesystem, not on the host. Bind-mount a host directory into the container at /data, recreate the container with that mapping, and point the file node at /data/logger.csv. If the error persists with the mount confirmed, align the mounted directory's ownership with the user the container process runs as.

On this page
  1. Why the filename resolves inside the container
  2. Checks that separate a path problem from a permission problem
  3. Map the host directory and recreate the container
  4. Point the file node at the mounted path
  5. When EACCES persists after the mount is confirmed
  6. Worked example: the /opt/plcnext logger write with the /data mount
  7. Verify on the controller and the decision for each case
  8. Questions asked

A Node-RED file node in a Docker container that reports EACCES: permission denied, mkdir '/opt/plcnext' is failing because the filename resolves inside the container's own filesystem, not on the PLCnext controller it runs on. Fixing the write permission alone would store the CSV inside the container, where it disappears when the container is removed. The fix has three parts: map a host directory into the container as /data, recreate the container so the mapping is active, and set the file node's filename to /data/logger.csv. If the error persists once the mount is confirmed, the mounted directory's ownership does not match the user the Node-RED process runs as, and that is the next thing to align.

Why the filename resolves inside the container #

The file node runs inside the Node-RED process in the container, so every filename it writes is resolved in that process's filesystem namespace. The flow sets the filename to /opt/plcnext/logger.csv. That path exists on the controller, but nothing links the container's /opt/plcnext to the controller's, and by default no such link exists. With createDir enabled, the node starts by creating the parent directory, which is exactly the operation in the error: the container process cannot create /opt/plcnext in its own filesystem root.

Two faults hide behind one message. The path is in the wrong namespace, so even a successful write would put the CSV in container storage, lost when the container is removed. And the container user has no write rights at that path, which is what turns the attempt into EACCES. Granting permissions without fixing the namespace would only move the file into the container. Check the namespace first.

Checks that separate a path problem from a permission problem #

  • Read the path in the error message. It names the path exactly as the container process sees it; if that path is not under the container side of a mount, the write is aimed at container storage.
  • Compare the file node's filename with the container side of the mount. The two must share their first path segment: a filename of /opt/plcnext/logger.csv cannot land in a mount whose container side is /data.
  • Inspect the mounts of the running container, not the command you intended to run. A mount takes effect when the container is created, so a container started before the argument was added carries no mapping. That is why creating the directory on the controller alone did not change the error.
  • With the mount confirmed, an error under the mounted path is an ownership question: compare the directory's owner and mode on the controller with the identity of the Node-RED process inside the container.
  • Verify on the controller, not only in the debug sidebar. A write that lands inside the container produces no error and still never reaches the controller's disk.

Map the host directory and recreate the container #

Create the directory on the controller first, so it exists with the ownership you intend:

mkdir /opt/plcnext/node-red-user-data

Then add the volume argument from the working arrangement to the command or compose entry that creates the container:

-v /opt/plcnext/node-red-user-data:/data

On a PLCnext controller the container runtime is Balena Engine, and the container guide for that platform uses the same pattern: a project folder on the controller, its example places one under /opt/plcnext, mounted into the container at a path such as /home/test. The argument form is identical; only the two paths change.

A mount is a create-time setting. Recreate the container, meaning remove it and create it again with the argument, so the running instance actually carries the mapping. Note that the mount alone does not fix the write either: the flow must address the container side of the mount, which is the next step. In this case the error cleared only once the container ran with the mount and the flow wrote under /data.

The same host-to-container mapping carries other resources besides files: Expose a serial port to Node-RED in a Docker container walks through the device case.

Point the file node at the mounted path #

Change the file node's filename from /opt/plcnext/logger.csv to /data/logger.csv, deploy the flow, and trigger one write from the inject node.

The other settings in the flow do no mapping and each needs a decision:

  • createDir set to true lets the node create the parent directory, here /data, which the mount already provides; it never maps anything.
  • appendNewline set to true adds the line break, so check the line endings in the CSV when you verify the content.
  • overwriteFile set to true makes every write replace the file, so each write leaves only its own row. If the logger must accumulate rows, disable overwrite so each write appends, and confirm over several writes that rows survive.

When EACCES persists after the mount is confirmed #

A mount exposes the host directory to the container; it does not grant write access to it. If the flow now writes under /data and the error is still EACCES, compare the directory's owner and mode on the controller with the identity of the Node-RED process in the container. A documented Docker case shows the shape of the problem: the container's user was UID 1000, and the mkdir kept failing until the target directory was created so that user could write to it.

Do the same here without trial and error: create /opt/plcnext/node-red-user-data before the container runs, then set its owner or group to the identity the container process runs as. The image's documentation states its default user, and the standard id utility, run inside the container through the engine's exec command, prints the running identity. Keep the grant as narrow as the data directory: a read-write mount hands the container process write access to everything under that host path, so widening the mount to the controller's system directories is never the fix.

Worked example: the /opt/plcnext logger write with the /data mount #

Inputs. The failing flow sets the file node's filename to /opt/plcnext/logger.csv with createDir true, overwriteFile true and appendNewline true. The working arrangement maps controller directory /opt/plcnext/node-red-user-data to container path /data. The run reports EACCES: permission denied, mkdir '/opt/plcnext'.

Rule. A bind mount makes everything under the host directory appear under the container path, and a file written under the container path lands on the controller with the container prefix swapped for the host prefix. A filename whose first path segment no mount covers never leaves the container's filesystem.

Arithmetic. As first configured, the filename starts with /opt/plcnext, and no mount covers that segment, so the path resolves inside the container: the node must create the parent directory there, the container user may not create directories at the filesystem root, and the write stops with EACCES. After the fix, the filename /data/logger.csv starts with the mount's container side /data, so the part beneath the mount is /logger.csv. Controller path = host side + remainder = /opt/plcnext/node-red-user-data + /logger.csv = /opt/plcnext/node-red-user-data/logger.csv.

Result. One CSV file, logger.csv, stored on the controller at /opt/plcnext/node-red-user-data/logger.csv, visible in ordinary controller file listings and safe from container removal.

Decision. An error naming any path outside /data is still the namespace fault: correct the mount and the filename, not the permissions. An error naming a path under /data with the mount confirmed in the running container is the ownership fault: align the directory owner with the container user. A file at the controller path after one triggered write closes the case.

Verify on the controller and the decision for each case #

Trigger one write and check for logger.csv in /opt/plcnext/node-red-user-data on the controller itself, through its console session, not only for a quiet debug sidebar. Then let the flow run for several write cycles and open the CSV: the rows, the line endings and whether earlier rows survive tell you whether the overwrite or append behavior matches what the logger must keep. When several containers will read that same CSV from host storage, How two Docker containers share one CSV file on an edge PC covers the sharing setup.

The decision for each case:

  • Error naming /opt/plcnext or any path with no mount over it: namespace fault. Create the host directory, recreate the container with -v /opt/plcnext/node-red-user-data:/data, and set the filename to /data/logger.csv.
  • Error under /data with the mount confirmed in the running container: permission fault. Create the directory in advance and set its owner or group to the container user's identity, keeping the mount limited to the data directory.
  • File present at the controller path: mapping correct. Confirm the retention behavior over multiple writes before leaving the flow in service.

If you are specifying a dedicated box for this logger rather than fixing the controller's mount, the same mount-and-path pattern runs unchanged on an industrial mini PC used as the edge data-collection host.

Questions asked

Why does a file write fail with mkdir in the error message?

The file node has createDir enabled, so before writing it makes sure the parent directory of the filename exists. That mkdir call is the first operation that touches the filesystem, so it is the one that returns EACCES. The setting only creates directories inside the filesystem the container process sees; it never maps a controller directory into the container.

Can a named volume be used instead of a controller directory?

Yes. A named volume also keeps the data outside the container, and the engine records where it lives on the controller. The arrangement that worked here mapped a controller directory directly with the volume argument, which keeps the host path explicit and easy to inspect. Whichever storage you choose, the file node must still address the container-side path such as /data/logger.csv, never a controller path.

Can the container write to /opt/plcnext on the controller directly?

Not unless you mount host storage at that exact container path. Without a mount, /opt/plcnext inside the container is the container's own path, and the Node-RED process cannot create it, which is the reported error. You could map a host directory to that same container path, but mapping the controller's system directory gives the container write access to paths the controller itself uses; a dedicated data directory keeps that exposure to one folder.

Where does the CSV go if the flow writes before any mount exists?

Into the container's writable filesystem layer. The write can succeed and the file can even be read back inside the container, yet nothing appears on the controller. That data disappears when the container is removed or recreated, which is easy to miss because a recreated container with the same name looks identical. Always confirm a new logger by looking for the file at the controller path.

Keep reading

  • Troubleshooting

    Node-RED in Docker uses the host clock, not its own time

    A Docker container does not keep its own clock: it reads the host Linux kernel's system time. Set the time inside Node-RED's container and you change the controller clock, not a container clock. Compare date -u on host and container, correct the controller's time synchronization, then check the timestamp field feeding the chart.

    Edge computing and IIoT

  • Troubleshooting

    Fix Node-RED Docker x509 Certificate Expired on an Edge PC

    The error x509: certificate has expired or is not yet valid means Docker reached the registry over TLS but the controller clock falls outside the certificate's validity dates. Set the correct date and an NTP server, confirm the controller shows the right UTC time, and re-run the same docker run command — the pull verifies on the next connection. Change nothing else first.

    Edge computing and IIoT

  • How-to

    How two Docker containers share one CSV file on an edge PC

    The vendor Node-RED container stores its CSV through a relative-path bind mount, so no other container can reach it. Declare a Docker named volume, mount it in both the Node-RED and Python services, point the write file node at /mydata, and mount the volume read-only on the Python side.

    Edge computing and IIoT