我正在尝试基于Firebird SQL服务器创建Dockerfile
。
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"]
但是当我构建并启动它时,它处于“正在启动”状态。
如果我执行docker top
,我会得到此
> 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
如果我评论我的Dockerfile CMD
的最后一行,我得到了这个:
> 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
请注意,如果没有CMD
我的容器启动Firebird SQL Server进程(fbguard
和fb_smp_server
),并且CMD
它没有并且卡在cron -f
。
我已经尝试复制父图像的ENTRYPOINT
和CMD
并与我的命令合并:
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"]
但是当我启动容器时,它会以exitcode 0退出并且不会启动。
>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
答案 0 :(得分:0)
解决。
我使用以下代码创建了一个名为init.sh
的新入口点脚本:
#!/bin/bash
service cron start
# import the parent script as source of this new one
source /usr/local/firebird/docker-entrypoint.sh
我的Dockerfile
现在是:
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"]
问题出在父图像ENTRYPOINT
和CMD
上。在我的形象中,我正在重新宣布他们,这就是容器没有启动的原因。
我认为docker不处理CMD
和ENTRYPOINT
的继承。