Search code examples
node.jsdockeralpine-linux

Docker cannot find module /bin/bash


I am trying to build a docker image for a nodejs web backend which currently looks like this:

FROM node:10-alpine

WORKDIR /usr/src/smart-brain-api

COPY ./ ./

RUN npm install

CMD ["/bin/bash"]

When I do docker run -it after building an image, I get this weird error

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module '/bin/bash'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

however if I edit the docker file and change CMD ["/bin/bash"] to CMD ["/bin/sh"] everything works

I am working on a macbook air 13, I don't know if that could be a factor.


Solution

  • alpine images doesn't have bash installed out of box. You need to install it separately.

    RUN apk update && apk add bash
    

    How to use bash with an Alpine based docker image?