Greetings!
[ My Desire ]
Have a process start running when a Container is built/started.
[ Troubles ]
The command to start the process, when added into the Dockerfile, causes the Container to not fail after the process initiates.
[ Attempts/Process ]
I have built a successfully running Dockerfile/Container, up to the point of executing the process that I want to start, and have tried a variety of approaches to get this to function properly, such as:
- Using CMD
- Using ENTRYPOINT
- Using RUN
- Creating a script, and using the previous to execute the script when starting
- Adding in Cron to execute the command and/or a script when starting
- Adding in Cron to execute the command and/or a script some time after the Container has been built and running
None of those have been successful, and to help round this out, after getting the Container running, I can enter the CLI and execute the command and it the process runs without any issue (also, I haven’t been successful in getting Cron to function either).
I can also call the script that contains the command, and runs with no issues from the CLI.
It seems to have an issue running the command/process during the Container startup if the command is within the Dockerfile as a line to execute.
[ Sample Dockerfile for Reference ]
Within this file, there are multiple attempts listed, and many that have been removed, and various combinations. The “/etc/init.d/process start” is how I normally start the process, and that command works just fine within the CLI of the container, but, as I mentioned earlier, it causes the Container to fail when trying to start it from the Dockerfile.
FROM ubuntu:20.10
RUN apt update && apt install openssh-server sudo openvpn ser2net network-manager cron nano -y
RUN mkdir /etc/new-dir
RUN mkdir /etc/new-dir/sub-dirCOPY local-dir/certs/* /etc/new-dir/sub-dir
COPY local-dir/config_dir/* /etc/new-dir
COPY local-dir/directory /usr/bin/directoryADD local-dir/crontab.txt /var/spool/cron/crontabs/root
RUN chmod 0644 /var/spool/cron/crontabs/root
RUN touch /var/log/cron.logCMD cron && tail -f /var/log/cron.log
#COPY docker-config/processStartup.sh /etc/new-dir
#ENTRYPOINT [“/etc/init.d/S01process start”]
#CMD “/etc/new-dir/processStartup.sh”#RUN crontab /crontab.txt
#RUN /processStartup.sh
#CMD [“/etc/init.d/process”, “start”]
#CMD [“/etc/init.d/process start”]