简体   繁体   中英

Node.js child_process.exec "/bin/sh: 1: docker: not found" error

I created a micro-service using the "Moleculer" framework. I used child_process.exec for running docker commands in a shell. I get " /bin/sh: 1: docker: not found " error.

const { exec } = require("child_process");
.
.
.
exec("docker --version", (error, stdout, stderr) => {
   if (error) {
      console.error(`exec error: ${error}`);
      return;
   }
   console.log(`stdout: ${stdout}`);
   console.log(`stderr: ${stderr}`);
   });

Tried giving absolute path as:

exec("/usr/bin/docker --version", (err...);

But still got the same error.

I am able to get the node version using:

exec("node --version", (err...);

I just had the same problem. The reason was simply that I had built a new image but the Docker client was not present in my container because I only did docker-compose restart <CONTAINER_NAME> and not docker-compose stop <CONTAINER_NAME> , docker-compose rm <CONTAINER_NAME> and docker-compose up -d <CONTAINER_NAME> .

https://stackoverflow.com/a/63281470/1707015

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM