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

Gerald Schneider
  • 19,757
  • 8
  • 52
  • 79
Serji
  • 1
  • 1

1 Answers1

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.

basvdlei
  • 1,296
  • 8
  • 13
  • 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 Apr 15 '22 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 Apr 16 '22 at 07:24
  • Thanks, I will try on that. will update – Serji Apr 17 '22 at 13:47
  • Hi , I have changed the application log from the customized path to /dev/stdout and it's resolved the issue. – Serji Apr 22 '22 at 09:10