cron 사용 가능한 알파인 도커 이미지 빌드

1 개요[ | ]

cron 사용 가능한 alpine 도커 이미지 빌드
cron 사용 가능한 알파인 도커 이미지 빌드

2 Dockerfile[ | ]

FROM alpine:3.11
RUN set -x \
&& apk add --no-cache \
  dcron \
&& echo '* * * * * date >> /test.txt' > /etc/crontabs/root
#CMD ["sh","-c","crond -b -L /var/log/cron.log && tail -f /var/log/cron.log"]
CMD ["sh","-c","crond -f"]

3 docker build[ | ]

$ docker build -t my_alpine_cron .
Sending build context to Docker daemon  4.096kB
Step 1/3 : FROM alpine:3.11
 ---> a187dde48cd2
Step 2/3 : RUN set -x && apk add --no-cache   dcron && echo '* * * * * date >> /test.txt' > /etc/crontabs/root
 ---> Using cache
 ---> fd736c5f9ef8
Step 3/3 : CMD ["sh","-c","crond -f"]
 ---> Using cache
 ---> d227ba60172f
Successfully built d227ba60172f
Successfully tagged my_alpine_cron:latest
$ docker images | grep my_alpine_cron
my_alpine_cron      latest              d227ba60172f        9 minutes ago       5.67MB

4 docker run[ | ]

$ docker run -d --name my_alpine_cron my_alpine_cron
557f3b4e50274bbc9e09ffe3aca6b0aba9d540179d580e65a79832f538c86584
$ docker ps
CONTAINER ID        IMAGE               COMMAND                   CREATED             STATUS              PORTS               NAMES
557f3b4e5027        my_alpine_cron      "/bin/sh -c 'crond -f'"   11 seconds ago      Up 10 seconds                           my_alpine_cron

5 cron 확인[ | ]

$ docker exec my_alpine_cron ps -ef
PID   USER     TIME  COMMAND
    1 root      0:00 crond -f
    7 root      0:00 ps -ef
$ docker exec my_alpine_cron crontab -l
* * * * * date >> /test.txt
$ docker exec my_alpine_cron cat /test.txt
Sun Apr 12 17:40:01 UTC 2020
Sun Apr 12 17:41:01 UTC 2020

6 Clean Up[ | ]

docker rm -f my_alpine_cron
docker rmi -f my_alpine_cron

7 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}