1

I'm trying to create a Dockerfile based on Firebird SQL server.

FROM jacobalberty/firebird:2.5.8-sc
ENV ISC_PASSWORD masterkey
RUN apt-get update && apt-get -y install cron
RUN echo "* * * * * root echo "Time is: $(date)" >>/var/log/cron.log 2>&1" /etc/cron.d/backup-cron
CMD ["cron", "-f"]

But when I build and start it, it stuck in status "Starting".

If I perform a docker top I get this

> docker top my-container
root                20838               20824               2                   19:42               ?                   00:00:00            /bin/bash /usr/local/firebird/docker-entrypoint.sh cron -f
root                20891               20838               0                   19:42               ?                   00:00:00            cron -f

And if I comment the last line of my Dockerfile CMD I get this:

> docker top my-container
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                20487               20475               0                   19:40               ?                   00:00:00            /bin/bash /usr/local/firebird/docker-entrypoint.sh /usr/local/firebird/bin/fbguard
root                20542               20487               0                   19:40               ?                   00:00:00            /usr/local/firebird/bin/fbguard
root                20543               20542               0                   19:40               ?                   00:00:00            /usr/local/firebird/bin/fb_smp_server

Note that without the CMD my container starts the Firebird SQL Server process (fbguard and fb_smp_server), and with the CMD it doesn't and stuck in the cron -f.

I already tried to copy the ENTRYPOINT and the CMD of the parent image and merge with my command:

FROM jacobalberty/firebird:2.5.8-sc
ENV ISC_PASSWORD masterkey
RUN apt-get update && apt-get -y install cron
RUN echo "* * * * * root echo "Time is: $(date)" >>/var/log/cron.log 2>&1" /etc/cron.d/backup-cron
ENTRYPOINT ["/bin/bash", "-c", "/usr/local/firebird/docker-entrypoint.sh", "&&", "cron", "-f"]
CMD ["/usr/local/firebird/bin/fbguard"]

But when I start the container it exit with exitcode 0 and doesn't starts.

>docker-compose up --build
Removing meu_teste
Building app
Step 1/6 : FROM jacobalberty/firebird:2.5.8-sc
 ---> 8c7d4de934c9
Step 2/6 : ENV ISC_PASSWORD masterkey
 ---> Using cache
 ---> 86770045ded3
Step 3/6 : RUN apt-get update && apt-get -y install cron
 ---> Using cache
 ---> 3a42b5d13eb1
Step 4/6 : RUN echo "* * * * * root echo "Time is: $(date)" >>/var/log/cron.log 2>&1" /etc/cron.d/backup-cron
 ---> Using cache
 ---> ad83425e8f1e
Step 5/6 : ENTRYPOINT ["/bin/bash", "-c", "/usr/local/firebird/docker-entrypoint.sh", "&&", "cron", "-f"]
 ---> Using cache
 ---> ba029a42c670
Step 6/6 : CMD ["/usr/local/firebird/bin/fbguard"]
 ---> Using cache
 ---> ab6b289934ac

Successfully built ab6b289934ac
Successfully tagged teste:latest
Recreating 847556ee975e_847556ee975e_meu_teste ... done
Attaching to meu_teste
meu_teste exited with code 0
Beto Neto
  • 3,962
  • 7
  • 47
  • 81
  • Possible duplicate of [How to run a cron job inside a docker container?](https://stackoverflow.com/questions/37458287/how-to-run-a-cron-job-inside-a-docker-container) – ajankuv Mar 06 '18 at 18:34

1 Answers1

1

Solved.

I created a new entrypoint script called init.sh with this code:

#!/bin/bash
service cron start
# import the parent script as source of this new one
source /usr/local/firebird/docker-entrypoint.sh

And my Dockerfile now is:

FROM jacobalberty/firebird:2.5.8-sc
ENV ISC_PASSWORD masterkey
RUN apt-get update && apt-get -y install cron
RUN (crontab -l ; echo "* * * * * echo "'"Now is $(date)"'" >> /var/log/cron.log") | crontab
ADD init.sh /init.sh
RUN chmod +x /init.sh
ENTRYPOINT ["/init.sh"]
CMD ["/usr/local/firebird/bin/fbguard"]

The problem was about the parent image ENTRYPOINT and CMD. At my image I was redeclaring they and this was the cause that the container wasn't starting.

I think docker doesn't handle inheritance of CMD and ENTRYPOINT.

Beto Neto
  • 3,962
  • 7
  • 47
  • 81