0

am unable to start the container from the docker image that builds from below Dockerfile It's failing if we add CMD to start filebeat or fluentd agent.

Dockerfile

#################################################
FROM node:12
#install pm2
RUN npm install pm2 -g
RUN apt update
#create dir and copy the code
RUN mkdir -p /home/devops/comera_registration_service/
WORKDIR  /home/devops/comera_registration_service/
COPY . .
#fluentd install
COPY fl.sh . 
RUN sh fl.sh
#install depend
RUN npm install
#start the app
CMD [ "pm2-runtime", "ecosystem.config.js" ]
CMD ["/etc/init.d/td-agent", "start" ]  
#opening port
EXPOSE 3010

enter image description here

enter image description here

1
  • Please don't post screenshots of text when you can just copy and paste the text instead. Commented Apr 15, 2022 at 16:58

1 Answer 1

1

The node:12 image has an entrypoint script. When an ENTRYPOINT is specified, Docker will use the values in CMD as parameters for this entrypoint command.

The parent image entrypoint can be disabled by adding the following to your Dockerfile:

ENTRYPOINT []

As a side note, when multiple CMD instructions are specified in a Dockerfile, only the last one will be set in the resulting image.

With the Dockerfile above and the parent entrypoint removed, /etc/init.d/td-agent will be PID 1 of the container. Since this is an init script, it will exit when it's done starting the daemon. When PID 1 is gone, the container will exit.

To run multiple programs inside a container, a wrapper script or process manager is needed. Note that this is generally not recommended. Eg. on Kubernetes the sidecar container pattern is preferred.

4
  • Thanks, I have tried as you told but when ever am giving CMD as starting fluentd agent it is exiting the container. ``` CMD ["/etc/init.d/td-agent", "start" ] ENTRYPOINT []
    – Serji
    Commented Apr 15, 2022 at 17:08
  • Updated the answer to include running multiple processes. Looking at your specific use-case, you should probably not add fluentd to the existing container image. I would recommend to look into running fluentbit/fluentd as a sidecar container.
    – basvdlei
    Commented Apr 16, 2022 at 7:24
  • Thanks, I will try on that. will update
    – Serji
    Commented Apr 17, 2022 at 13:47
  • Hi , I have changed the application log from the customized path to /dev/stdout and it's resolved the issue.
    – Serji
    Commented Apr 22, 2022 at 9:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .