Initial commit
This commit is contained in:
parent
69dd8c7332
commit
571e0f3282
6 changed files with 86 additions and 0 deletions
28
Dockerfile
Normal file
28
Dockerfile
Normal file
|
@ -0,0 +1,28 @@
|
|||
FROM microsoft/dotnet:1.1.1-sdk
|
||||
|
||||
ARG BUILDCONFIG=DEBUG
|
||||
|
||||
# Install Cron
|
||||
RUN apt-get update -qq && apt-get -y install cron -qq --force-yes
|
||||
|
||||
# Copy project files to avoid restoring packages if they haven't changed
|
||||
COPY . /app/.
|
||||
WORKDIR /app/
|
||||
|
||||
# Set up schedule
|
||||
ADD schedule /etc/cron.d/schedule
|
||||
RUN chmod 0644 /etc/cron.d/schedule
|
||||
|
||||
# Create log file
|
||||
RUN touch /var/log/cron.log
|
||||
RUN chmod 0666 /var/log/cron.log
|
||||
|
||||
# Publish dotnet core app
|
||||
RUN dotnet restore
|
||||
RUN dotnet publish -c $BUILDCONFIG -o out
|
||||
|
||||
# Volume required for tail command
|
||||
VOLUME /var/log
|
||||
|
||||
# Run Cron
|
||||
CMD /usr/sbin/cron && tail -f /var/log/cron.log
|
12
Program.cs
Normal file
12
Program.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
|
||||
namespace test_dotnet
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine($"This program should be running on a schedule: {DateTime.Now}");
|
||||
}
|
||||
}
|
||||
}
|
21
README.md
Normal file
21
README.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
# .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.
|
||||
|
||||
The docker image makes use of cron which is a unix utility for running commands on a schedule.
|
||||
|
||||
The docker file attached does the following:
|
||||
1. Installs cron on the standard microsoft/dotnet:1.1.1-sdk image.
|
||||
2. Copies your application files across to the docker image.
|
||||
3. Copies the schedule file across to the docker image.
|
||||
4. Restores and Publishes your dotnet core image.
|
||||
5. 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 Dockerfile, schedule file dockerignore file and docker-compose.yml (if you are not using your own).
|
||||
|
||||
You need to modify the schedule file to reference the dll of your console app.
|
||||
|
||||
Then run:
|
||||
|
||||
`docker-compose up`
|
6
docker-compose.yml
Normal file
6
docker-compose.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
version: "3"
|
||||
|
||||
services:
|
||||
console:
|
||||
build: .
|
||||
container_name: recurring-console
|
8
dotnet-cron.csproj
Normal file
8
dotnet-cron.csproj
Normal file
|
@ -0,0 +1,8 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp1.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
11
schedule
Normal file
11
schedule
Normal file
|
@ -0,0 +1,11 @@
|
|||
* * * * * root dotnet /app/out/dotnet-cron.dll >> /var/log/cron.log 2>&1
|
||||
|
||||
#* * * * * *
|
||||
#| | | | | |
|
||||
#| | | | | +-- Year (range: 1900-3000)
|
||||
#| | | | +---- Day of the Week (range: 1-7, 1 standing for Monday)
|
||||
#| | | +------ Month of the Year (range: 1-12)
|
||||
#| | +-------- Day of the Month (range: 1-31)
|
||||
#| +---------- Hour (range: 0-23)
|
||||
#+------------ Minute (range: 0-59)
|
||||
# Cron requires a blank space at the end of the file so leave this here.
|
Loading…
Reference in a new issue