它是我的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
当我输入docker run <image name>
时,我的容器必须运行node index.js
我必须为此做些什么?
答案 0 :(得分:1)
Janez注释将起作用,但是,如果您的容器必须以'node index.js'开头,您将需要使用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"]
如果您想了解更多关于两者之间的差异,或者如何将它们组合在一起,那么Stackoverflow中已经对ENTYRYPOINT vs CMD进行了广泛的讨论,例如。
ENTRYPOINT ["node"]
CMD ["index.js"]
相反,您可以使用备用的js文件调用容器,即。
docker run -it <image-name> test.js
现在容器将启动并运行node test.js
而不是