-2

I have a Dockerfile looking like this:

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

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:

/ # 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.

hc0re
  • 1,806
  • 2
  • 26
  • 61
  • 2
    `ENTRYPOINT` defines executable when container start, and `CMD` define default argument to `ENTRYPOINT`. https://stackoverflow.com/questions/21553353/what-is-the-difference-between-cmd-and-entrypoint-in-a-dockerfile – Enix Feb 27 '19 at 13:29

1 Answers1

2

Entrypoint sets the command and parameters that will be executed first when a container is run.

CMD provide defaults when executing a container. 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. Here is an example Dockerfile that uses both instructions.

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.

Paulo Pedroso
  • 3,555
  • 2
  • 29
  • 34