Important
Configuration keys are not case sensitive
This job is executed inside a running container. Similar to docker exec
- Schedule *
- description: When the job should be executed. E.g. every 10 seconds or every night at 1 AM.
- value: String, see Scheduling format of the Go implementation of
cron. E.g.@every 10sor0 0 1 * * *(every night at 1 AM). Note: the format starts with seconds, instead of minutes. - default: Required field, no default.
- Command *
- description: Command you want to run inside the container.
- value: String, e.g.
touch /tmp/example - default: Required field, no default.
- Container *
- description: Name of the container you want to execute the command in.
- value: String, e.g.
nginx-proxy - default: Required field, no default.
- User
- description: User as which the command should be executed, similar to
docker exec --user <user> - value: String, e.g.
www-data - default:
root
- description: User as which the command should be executed, similar to
- tty
- description: Allocate a pseudo-tty, similar to
docker exec -t. See this Stack Overflow answer for more info. - value: Boolean, either
falseortrue - default:
false
- description: Allocate a pseudo-tty, similar to
- Environment
- description: Environment variables you want to set in the running container. Note: exec configuration Env is only supported in Docker API#1.25 and above
- value: Same format as used with
-eflag withindocker run. For example:FOO=bar- INI config:
Environmentsetting 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:
- default: Optional field, no default.
[job-exec "flush-nginx-logs"]
schedule = @hourly
container = nginx-proxy
command = /bin/bash /flush-logs.sh
user = www-data
tty = falseofelia container should be started after nginx container, to be able to read its labels, because real time labels reading is not supported yet.
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" \
nginxThis 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 * (1,2)
- description: When the job should be executed. E.g. every 10 seconds or every night at 1 AM.
- value: String, see Scheduling format of the Go implementation of
cron. E.g.@every 10sor0 1 * * *(every night at 1 AM). - default: Required field, no default.
- Command (1)
- description: Command you want to run inside the container.
- value: String, e.g.
touch /tmp/example - default: Default container command
- Image (1)
- description: Image you want to use for the job.
- value: String, e.g.
nginx:latest - default: No default. If left blank, Ofelia assumes you will specify a container to start (situation 2).
- User (1)
- description: User as which the command should be executed, similar to
docker run --user <user> - value: String, e.g.
www-data - default:
root
- description: User as which the command should be executed, similar to
- Network (1)
- description: Connect the container to this network
- value: String, e.g.
backend-proxy - default: Optional field, no default.
- Hostname (1)
- description: Define the hostname of the instantiated container
- value: String, e.g.
test-server - default: Optional field, no default.
- Delete (1)
- description: Delete the container after the job is finished. Similar to
docker run --rm - value: Boolean, either
trueorfalse - default:
true
- description: Delete the container after the job is finished. Similar to
- Container (2)
- description: Name of the container you want to start.
- value: String, e.g.
nginx-proxy - default: Required field in case parameter
imageis not specified, no default.
- tty (1,2)
- description: Allocate a pseudo-tty, similar to
docker exec -t. See this Stack Overflow answer for more info. - value: Boolean, either
trueorfalse - default:
false
- description: Allocate a pseudo-tty, similar to
- Volume
- description: Mount host machine directory into container as a bind mount
- value: Same format as used with
-vflag withindocker run. For example:/tmp/test:/tmp/test:ro- INI config:
Volumesetting 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:
- default: Optional field, no default.
- Volumes-From
- description: Use the volumes from another container.
- value: The name of the container, from which the volumes will be used.
- INI config: setting can be provided multiple times for multiple mounts.
- Labels config: multiple mounts has to be provided as JSON array:
["container-foo", "bar-container"]
- default: Optional field, no default.
- Environment
- description: Environment variables you want to set in the running container.
- value: Same format as used with
-eflag withindocker run. For example:FOO=bar- INI config: 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"]
- default: Optional field, no default.
[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
environment = BAZ=quxThen you can check output in host machine file /tmp/test/date
Docker run job has to be configured as labels on the ofelia container itself, because it is going to start new container:
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'" \
mcuadros/ofelia:latest daemon --dockerRuns 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 *
- description: When the job should be executed. E.g. every 10 seconds or every night at 1 AM.
- value: String, see Scheduling format of the Go implementation of
cron. E.g.@every 10sor0 1 * * *(every night at 1 AM). - default: Required field, no default.
- Command *
- description: Command you want to run on the host.
- value: String, e.g.
touch test.txt - default: Required field, no default.
- Dir
- description: Base directory to execute the command.
- value: String, e.g.
/tmp/sandbox/ - default: Current directory
- Environment
- description: Environment variables you want to set for the executed command.
- value: Same format as used with
-eflag withindocker run. For example:FOO=bar- INI config:
Environmentsetting 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:
- default: Optional field, no default.
[job-local "create-file"]
schedule = @every 15s
command = touch test.txt
dir = /tmp/Docker run job has to be configured as labels on the ofelia container itself, because it will be executed inside ofelia container
docker run -it --rm \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
--label ofelia.enabled=true \
--label ofelia.job-local.create-file.schedule="@every 15s" \
--label ofelia.job-local.create-file.image="alpine:latest" \
--label ofelia.job-local.create-file.command="touch test.txt" \
--label ofelia.job-local.create-file.dir="/tmp/" \
mcuadros/ofelia:latest daemon --dockerThis job can be used to:
- To run a command inside a new "run-once" service, for running inside a swarm.
- Schedule * (1,2)
- description: When the job should be executed. E.g. every 10 seconds or every night at 1 AM.
- value: String, see Scheduling format of the Go implementation of
cron. E.g.@every 10sor0 1 * * *(every night at 1 AM). - default: Required field, no default.
- Command (1, 2)
- description: Command you want to run inside the container.
- value: String, e.g.
touch /tmp/example - default: Default container command
- Image * (1)
- description: Image you want to use for the job.
- value: String, e.g.
nginx:latest - default: No default. If left blank, Ofelia assumes you will specify a container to start (situation 2).
- Network (1)
- description: Connect the container to this network
- value: String, e.g.
backend-proxy - default: Optional field, no default.
- delete (1)
- description: Delete the container after the job is finished.
- value: Boolean, either
trueorfalse - default:
true
- User (1,2)
- description: User as which the command should be executed.
- value: String, e.g.
www-data - default:
root
- tty (1,2)
- description: Allocate a pseudo-tty, similar to
docker exec -t. See this Stack Overflow answer for more info. - value: Boolean, either
trueorfalse - default:
false
- description: Allocate a pseudo-tty, similar to
[job-service-run "service-executed-on-new-container"]
schedule = 0,20,40 * * * *
image = ubuntu
network = swarm_network
command = touch /tmp/example