Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 717
miles-blaq Avatar asked Dec 30 '22 21:12

miles-blaq


2 Answers

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?

like image 143
Harsh Gupta Avatar answered Jan 02 '23 12:01

Harsh Gupta


Like the other answer said you need to install bash first as alpine doesn't comes with bash installed. You need to install it with:

RUN apk update && apk add bash

Then you can switch the default shell from sh to bash with this line in your dockerfile

SHELL ["/bin/bash", "-c"]

The dockerfile should look like something like this

FROM node:10-alpine
RUN apk update && apk add bash
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
CMD bash # If you want to override CMD

Then you can launch you container with this line

docker run -it --rm <image-name> bash

or if you have overrided CMD you can simply do

docker run -it --rm <image-name>
like image 30
severin.julien Avatar answered Jan 02 '23 11:01

severin.julien