This job is executed inside a running container, similar to docker exec
.
schedule
: string- When the job should be executed. E.g. every 10 seconds or every night at 1 AM.
command
: string- Command you want to run inside the container.
container
: string- Name of the container you want to execute the command in.
user
: string =root
- User as which the command should be executed, similar to
docker exec --user <user>
- User as which the command should be executed, similar to
tty
: boolean =false
- Allocate a pseudo-tty, similar to
docker exec -t
. See this Stack Overflow answer for more info.
- Allocate a pseudo-tty, similar to
environment
- Environment variables you want to set in the running container. Note: only supported in Docker API v1.25 and above
- Same format as used with
-e
flag withindocker run
. For example:FOO=bar
- INI config:
Environment
setting can be provided multiple times for multiple environment variables. - Labels config: multiple environment variables has to be provided as JSON array:
["FOO=bar", "BAZ=qux"]
- INI config:
no-overlap
: boolean =false
- Prevent that the job runs concurrently
[job-exec "flush-nginx-logs"]
schedule = @hourly
container = nginx-proxy
command = /bin/bash /flush-logs.sh
user = www-data
tty = false
docker run -it --rm \
--label ofelia.enabled=true \
--label ofelia.job-exec.flush-nginx-logs.schedule="@hourly" \
--label ofelia.job-exec.flush-nginx-logs.command="/bin/bash /flush-logs.sh" \
--label ofelia.job-exec.flush-nginx-logs.user="www-data" \
--label ofelia.job-exec.flush-nginx-logs.tty="false" \
nginx
This job can be used in 2 situations:
- To run a command inside of a new container, using a specific image, similar to
docker run
- To start a stopped container, similar to
docker start
schedule
: string (1, 2)- When the job should be executed. E.g. every 10 seconds or every night at 1 AM.
command
: string = default container command (1)- Command you want to run inside the container.
image
: string (1)- Image you want to use for the job.
- If left blank, Ofelia assumes you will specify a container to start (situation 2).
user
: string =root
(1)- User as which the command should be executed, similar to
docker run --user <user>
- User as which the command should be executed, similar to
network
: string (1)- Connect the container to this network
hostname
: string (1)- Define the hostname of the instantiated container, e.g.
test-server
- Define the hostname of the instantiated container, e.g.
delete
: boolean =true
(1)- Delete the container after the job is finished. Similar to
docker run --rm
- Delete the container after the job is finished. Similar to
container
: string (2)- Name of the container you want to start.
- Required field in case parameter
image
is not specified, no default.
tty
: boolean =false
(1, 2)- Allocate a pseudo-tty, similar to
docker exec -t
. See this Stack Overflow answer for more info.
- Allocate a pseudo-tty, similar to
volume
:- Mount host machine directory into container as a bind mount
- Same format as used with
-v
flag withindocker run
. For example:/tmp/test:/tmp/test:ro
- INI config:
Volume
setting can be provided multiple times for multiple mounts. - Labels config: multiple mounts has to be provided as JSON array:
["/test/tmp:/test/tmp:ro", "/test/tmp:/test/tmp:rw"]
- INI config:
environment
- Environment variables you want to set in the running container.
- Same format as used with
-e
flag withindocker run
. For example:FOO=bar
- INI config:
Environment
setting can be provided multiple times for multiple environment variables. - Labels config: multiple environment variables has to be provided as JSON array:
["FOO=bar", "BAZ=qux"]
- INI config:
no-overlap
: boolean =false
- Prevent that the job runs concurrently
[job-run "print-write-date"]
schedule = @every 5s
image = alpine:latest
command = sh -c 'date | tee -a /tmp/test/date'
volume = /tmp/test:/tmp/test:rw
environment = FOO=bar
Then you can check output in host machine file /tmp/test/date
docker run -it --rm \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
--label ofelia.enabled=true \
--label ofelia.job-run.print-write-date.schedule="@every 5s" \
--label ofelia.job-run.print-write-date.image="alpine:latest" \
--label ofelia.job-run.print-write-date.volume="/tmp/test:/tmp/test:rw" \
--label ofelia.job-run.print-write-date.environment="FOO=bar" \
--label ofelia.job-run.print-write-date.command="sh -c 'date | tee -a /tmp/test/date'" \
netresearch/ofelia:latest daemon
Runs the command on the host running Ofelia.
Note: In case Ofelia is running inside a container, the command is executed inside the container. Not on the Docker host.
schedule
: string- When the job should be executed. E.g. every 10 seconds or every night at 1 AM.
command
: string- Command you want to run on the host.
dir
: string =$(pwd)
- Base directory to execute the command.
environment
- Environment variables you want to set for the executed command.
- Same format as used with
-e
flag withindocker run
. For example:FOO=bar
- INI config:
Environment
setting can be provided multiple times for multiple environment variables. - Labels config: multiple environment variables has to be provided as JSON array:
["FOO=bar", "BAZ=qux"]
- INI config:
no-overlap
: boolean =false
- Prevent that the job runs concurrently
[job-local "create-file"]
schedule = @every 15s
command = touch test.txt
dir = /tmp/
This job can be used to:
- To run a command inside a new
run-once
service, for running inside a swarm.
schedule
: string (1, 2)- When the job should be executed. E.g. every 10 seconds or every night at 1 AM.
command
: string = default container command (1, 2)- Command you want to run inside the container.
image
: string (1)- Image you want to use for the job.
- If left blank, Ofelia assumes you will specify a container to start (situation 2).
network
: string (1)- Connect the container to this network
delete
: boolean =true
(1)- Delete the container after the job is finished.
user
: string =root
(1, 2)- User as which the command should be executed.
tty
: boolean =false
(1, 2)- Allocate a pseudo-tty, similar to
docker exec -t
. See this Stack Overflow answer for more info.
- Allocate a pseudo-tty, similar to
no-overlap
: boolean =false
- Prevent that the job runs concurrently
[job-service-run "service-executed-on-new-container"]
schedule = 0,20,40 * * * *
image = ubuntu
network = swarm_network
command = touch /tmp/example