具有以下 Dockerfile
FROM ubuntu:20.04
FROM postgres:17.0
##### packages needed that dont come with the image of ubuntu:20.04
RUN apt-get update \
&& apt-get install -y bash \
&& apt-get install -y cron \
&& apt-get install nano
#&& apt-get install -y iputils-ping
#RUN sudo apt install postgresql
COPY backup.sh /usr/local/bin/
COPY setup.sh /usr/local/bin/
WORKDIR /usr/local/bin/
RUN chmod +x backup.sh
RUN chmod +x setup.sh
RUN ./setup.sh
# Add the cron job to the crontab
RUN crontab -l | { cat; echo "* * * * * /usr/local/bin/backup.sh 10 'localhost' '5432' 'postgres' 'xxxxx' 'dvdrental' >> /mnt/backups/backup.log 2>&1"; } | crontab -
CMD ["/bin/bash","cron"]
构建容器的命令
sudo docker build --no-cache -t hcorte/backup_container .
运行容器的命令
sudo docker run --name ubuntu -v /mnt/backups/:/mnt/backups/ --add-host host.docker.internal:host-gateway -itd hcorte/backup_container bash
当附加到容器并运行命令时service cron status
返回
cron 没有运行...失败!
但是没有 CMD ["/bin/bash","cron"]
指示启动 cron 服务吗?Dockerfile 需要进行哪些更改才能让 cron 服务在开始时就启动?