I created a docker image for a cron job (script backup.sh) - it copies files to the remote server for a backup. but first - when container starts I need to create ssh keys and add it to authorized_keys on the remote server, so I can connect via rsync.
I can't figure out how could I do two tasks on the container start - launch script authorize.sh and cron
I tried to call authorize.sh within the script backup.sh, but it would be called always at the same time in multiple containers and those ssh key overwrites each other, that's why I need to do it on container start, not inside the cron script
I can't call the script in the dockerfile on image build, as the remote server connections are passed as environment variables
I've tried instead of CMD ['crond', '-f', '-d', '8'] do CMD ['authorize.sh', '-f', '-d', '8'] and add crond -f inside the authorize script, but container stops after finishing authorize.sh
Dockerfile
FROM alpine:3.6
RUN apk update; \
apk upgrade;
RUN apk add bash openssh-client sshpass rsync
RUN mkdir -p /var/export/
COPY backup.sh /usr/local/bin/backup.sh
RUN chmod +x /usr/local/bin/backup.sh
RUN echo '0 */8 * * * /usr/local/bin/backup.sh' > /etc/crontabs/root
WORKDIR /var/export/
CMD ["crond", "-f", "-d", "8"]