Add sample on how to run a cron task in a docker container
This commit is contained in:
parent
42fb4a0d19
commit
5538470a5d
12
Dockerfile
Normal file
12
Dockerfile
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# Dockerfile to create image with cron services
|
||||||
|
FROM ubuntu:latest
|
||||||
|
|
||||||
|
# Install Cron
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get -y install cron \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
RUN useradd test
|
||||||
|
|
||||||
|
# Run the command on container startup
|
||||||
|
CMD crontab -u test /home/test/cron/crontab-file && cron -f
|
1
crontab-file
Normal file
1
crontab-file
Normal file
@ -0,0 +1 @@
|
|||||||
|
* * * * * bash /test/cron/task.sh
|
8
docker-compose.yml
Normal file
8
docker-compose.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
cron:
|
||||||
|
build: .
|
||||||
|
volumes:
|
||||||
|
- ./output:/output
|
||||||
|
- ./:/home/test/cron
|
||||||
|
|
19
output/out.txt
Normal file
19
output/out.txt
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
Hello World at Thu Nov 30 21:45:01 UTC 2023
|
||||||
|
Hello World at Thu Nov 30 21:46:01 UTC 2023
|
||||||
|
Hello World at Thu Nov 30 21:47:01 UTC 2023
|
||||||
|
Hello World at Thu Nov 30 21:48:01 UTC 2023
|
||||||
|
Hello World at Thu Nov 30 21:52:01 UTC 2023
|
||||||
|
Hello World at Thu Nov 30 21:53:01 UTC 2023
|
||||||
|
Hello World at Thu Nov 30 21:54:01 UTC 2023
|
||||||
|
Hello World at Thu Nov 30 21:55:01 UTC 2023
|
||||||
|
Hello World at Thu Nov 30 21:56:01 UTC 2023
|
||||||
|
Hello World at Thu Nov 30 21:57:01 UTC 2023
|
||||||
|
Hello World at Thu Nov 30 22:02:01 UTC 2023
|
||||||
|
Hello World at Thu Nov 30 22:03:01 UTC 2023
|
||||||
|
Hello World at Thu Nov 30 22:04:01 UTC 2023
|
||||||
|
Hello World at Thu Nov 30 22:05:01 UTC 2023
|
||||||
|
Hello World at Thu Nov 30 22:06:01 UTC 2023
|
||||||
|
Hello World at Thu Nov 30 22:07:01 UTC 2023
|
||||||
|
Hello World at at at at at Thu Nov 30 22:08:01 UTC 2023
|
||||||
|
Hello World at at at at at Thu Nov 30 22:09:01 UTC 2023: /root
|
||||||
|
Hello World at at at at at Thu Nov 30 22:10:01 UTC 2023: /root
|
Loading…
Reference in New Issue
Block a user