简体   繁体   English

如何在dockerfile中没有CMD或ENTRYPOINT的情况下在启动时运行进程?

[英]how to run a process on startup without CMD or ENTRYPOINT in a dockerfile?

Here's some example dockerfile:这是一些示例 dockerfile:

FROM ubuntu:18.04
RUN apt-get install xvfb

CMD Xvfb :0 -ac # <-- I need this to run on start up, no as CMD

CMD node programThatNeedsXvfbRunning.js

I need Xvfb :0 -ac to be running inside the image by default, so that I can do docker run my-container someCustomCmdThatRequiresXvfbrunning默认情况下,我需要Xvfb :0 -ac在图像内运行,以便我可以执行docker run my-container someCustomCmdThatRequiresXvfbrunning

I know I could do Xvfb :0 -ac & node myapp but that seems stupid to have to do this every time.我知道我可以做Xvfb :0 -ac & node myapp但每次都必须这样做似乎很愚蠢。

Try this Dockerfile :试试这个Dockerfile

FROM ubuntu:18.04
RUN apt-get install xvfb

ENTRYPOINT [ "Xvfb", ":0", "-ac" ]

Then run it as:然后运行它:

docker run <image> cmd1 cmd2

This should behave as if you ran:这应该表现得好像你跑了:

Xvfb :0 -ac cmd1 cmd2

Is this what you want?这是你想要的吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM