简体   繁体   English

Dockerfile 中的 CMD 后跟 ENTRYPOINT 的问题

[英]Problem with CMD followed by ENTRYPOINT in Dockerfile

I have a Dockerfile looking like this:我有一个看起来像这样的 Dockerfile:

FROM quorumengineering/quorum:latest

RUN apk add nodejs npm
RUN cd ~
RUN npm i axios
COPY watcher.js .
ENTRYPOINT [ "geth", "--raft", "--raftjoinexisting", "1" ]
CMD "node watcher.js"

What I'm trying to achieve is to run geth with parameters and then run nodejs app watcher.js我想要实现的是使用参数运行 geth 然后运行 ​​nodejs app watcher.js

Container image is building correctly, using command:使用命令正确构建容器镜像:

docker build -t somename .

And it is starting properly using the command:它使用以下命令正确启动:

docker run -d somename

But when I docker exec -it containerID sh and run ps i get:但是当我docker exec -it containerID sh并运行 ps 我得到:

/ # ps
PID   USER     TIME  COMMAND
    1 root      0:01 geth --raft --raftjoinexisting 1 /bin/sh -c "node watcher.js"
   16 root      0:00 sh
   23 root      0:00 ps

It looks like it is running both commands in one line... The geth command is running perfectly, but the nodejs app is not starting... docker logs is giving me no interesting output.看起来它在一行中运行两个命令...... geth命令运行完美,但 nodejs 应用程序没有启动...... docker docker logs没有给我任何有趣的输出。

Entrypoint sets the command and parameters that will be executed first when a container is run.入口点设置在容器运行时将首先执行的命令和参数。

CMD provide defaults when executing a container. CMD 在执行容器时提供默认值。 These will be executed after the entrypoint.这些将在入口点之后执行。

Docker recommends using ENTRYPOINT to set the image's main command, and then using CMD as the default flags. Docker 推荐使用 ENTRYPOINT 来设置镜像的主命令,然后使用 CMD 作为默认标志。 Here is an example Dockerfile that uses both instructions.这是一个使用这两个指令的示例 Dockerfile。

FROM ubuntu
ENTRYPOINT ["top", "-b"]
CMD ["-c"]

I recommend you creating a bash script with the startup commands you need, adding it to the container and using it in CMD or ENTRYPOINT.我建议您使用所需的启动命令创建一个 bash 脚本,将其添加到容器中并在 CMD 或 ENTRYPOINT 中使用它。

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

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