1

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...);
  • Docker is installed on your machine and does same cmd is working from cmd line? Just want to be sure before thinking anything else. – Rohit Jindal Apr 21 '19 at 18:21
  • Is it alpine based image, alpine does not has sh or bash in the image. – Akash Sharma Apr 23 '19 at 08:45
  • @RohitJindal yes, docker is installed on my machine and commands work fine in the terminal. – Kell Maresh Apr 24 '19 at 10:56
  • @AakashSharma I am getting an error from /bin/sh that docker is not found. So, sh must exist in the image I am using. – Kell Maresh Apr 24 '19 at 10:58
  • The micro-service from which I use child_process to run shell/docker commands is running inside a docker container (In that container, docker wouldn't be installed). So I think it won't have access to the docker installed on my machine from within that docker container. I was confused because for some reason I was able to run "ls" command to see directory contents at the path where docker is installed on my machine. – Kell Maresh Apr 24 '19 at 11:03

1 Answers1

0

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

qräbnö
  • 2,722
  • 27
  • 40