Giter VIP home page Giter VIP logo

dotnetcron's Introduction

.Net Core console app running in a schedule in Docker

This is an example project showing you how to run a console app in a schedule in a docker container.

For more information see a full breakdown on my blog: https://www.alexhyett.com/scheduled-dotnet-core-console/

The docker image makes use of cron which is a unix utility for running commands on a schedule.

The issue I came across with running console apps in cron is that the environment variables aren't visible to cron jobs. You have to specify the environment variables up front before running your job.

However, the whole point of Docker is not to have a hardcoded values which are likely to change between environments.

You therefore need to copy the environment variables to a script when your container starts and then set up your environment as part of the cron script.

The docker file attached does the following:

  1. Copies your project files across and restores them.
  2. Copies your application files across to the docker image.
  3. Publishes your application to the out location.
  4. Creates a new 2.0.0-runtime image.
  5. Copies your published app to the new image.
  6. Installs cron into the runtime image.
  7. Copies scripts and schedule file, removes carrage returns and sets permissions
  8. Copies environment variables so that cron can access them.
  9. Runs cron and outputs the contents of the /var/log/cron.log file to the screen.

How to use

To use this within your own dotnet core console app you will need the following files:

  • Dockerfile
  • schedule
  • export_env.sh
  • run_app.sh
  • .dockerignore
  • docker-compose.yml

You need to modify the run_app.sh file to reference the dll of your console app and the schedule file if you want it to run on a different schedule other than once a minute.

Then run:

docker-compose up

dotnetcron's People

Contributors

alex-hyett-cko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.