0

Good morning, I am using a node application in a docker container. In a node route I would like to be able to execute a command on the docker host as a host.

I tried the command (result: "/host no usch file or directory")

const exec = require('child_process')

exec("chroot /host bash -c 'ls -l'")

But withou success

m mrdi
  • 1
  • 1
  • Inside a container, you would not be able to execute commands on the host. If you need to run commands on the host, you could use some script on the host instead. – liginity Jun 30 '23 at 09:12
  • A specific design goal of Docker is that you can't do this. You can't run commands directly on the host, and you can't chroot(8) out of the container environment to use the host filesystem. The linked question describes a complex workaround using bind-mounted named pipes but there isn't really a better approach. – David Maze Jun 30 '23 at 10:43

0 Answers0