0

It's beginning of my dockerfile:

FROM ubuntu:latest
RUN apt-get update
RUN apt-get install node
RUN apt-get install npm
RUN apt-get install mongo
RUN mkdir app
COPY . app/
WORKDIR app

When I input docker run <image name>, my container must run node index.js What I must do for it?

Bukharov Sergey
  • 9,767
  • 5
  • 39
  • 54

1 Answers1

1

Janez comment will work, however, if your container MUST start with 'node index.js' you will want to use ENTRYPOINT:

FROM ubuntu:latest
RUN apt-get update
RUN apt-get install node
RUN apt-get install npm
RUN apt-get install mongo
RUN mkdir app
COPY . app/
WORKDIR app
ENTRYPOINT ["node", "index.js"]

There is an extensive discussion on ENTYRYPOINT vs CMD here in Stackoverflow already if you'd like to know more about the difference between the two, or how they can be combined e.g.

ENTRYPOINT ["node"]
CMD ["index.js"]

with that instead you could call the container with an alternate js file i.e.

docker run -it <image-name> test.js

and now the container would start and run node test.js instead

Community
  • 1
  • 1
thoth
  • 1,112
  • 2
  • 9
  • 15