Beginner's tips for Rancher


I would like to introduce some tips for Rancher’s beginner.

🏀 Add cron configuration

If you want Rancher to run script regularly:

  • (1) Launch a stack for cron Rancher Cron Service
  • (2) Add setting(label) for corn in docker-compose.yml

Launch a stack for cron

Launch a stack for cron Rancher Cron Service.
Even if there are multiple hosts, we will take care of them collectively, so only one is fine.

docker-compose.rancher-cron.yml is as follows:

version: '3.5'
services:
rancher-cron:
labels:
io.rancher.container.create_agent: 'true'
io.rancher.container.agent.role: environment
image: socialengine/rancher-cron:0.2.0

rancher-compose.yml is as follows:

version: '2'
services:
app:
scale: 1
start_on_create: true

After creating the above files, you can start the cron stack on Rancher with the following command.

rancher up -d --pull --force-upgrade --recreate --stack rancher-cron --file ./conf/docker-compose.rancher-cron.yml --rancher-file ./conf/rancher-compose.yml

Add setting(label) for corn in docker-compose.yml

あとは実際にcronで定期的に実行したいスクリプトにcom.socialengine.rancher-cron.schedule: 0 */15 * * * *といったラベルを追加しておきます。

Add a label such as com.socialengine.rancher-cron.schedule: 0 * / 15 * * * * to your docker-compose.yml for service.

docker-compose.some-script.yml is as follows:

version: '3.5'
services:
app:
image: some-docker-image:latest
command: '/script/to/do_something.sh'
working_dir: "/app"
tty: true
stdin_open: true
labels:
com.socialengine.rancher-cron.schedule: 0 */15 * * * *
io.rancher.container.start_once: 'true'

rancher-compose.yml is as follows:

version: '2'
services:
app:
scale: 1
start_on_create: true

After creating the above files, you can start the cron stack on Rancher with the following command.

rancher rm --stop some-script
rancher up -d --pull --force-upgrade --recreate --stack rsome-script --file ./conf/docker-compose.some-script.yml --rancher-file ./conf/rancher-compose.yml

🗽 References

🖥 Recommended VPS Service

VULTR provides high performance cloud compute environment for you. Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour). In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!