简体   繁体   中英

Nodejs API Cronjob node-schedule not running inside docker container

Created an API to run some scheduled jobs with Nodejs which is running in a docker container.

exports.createAutoJobs = async (req, res, next) => {
console.log("Request received")
    cron.schedule('* * * * *', () => {
        console.log('Running');
    });
}

The above code is printing "Running" for every minute But for the same code adding a custom time pattern is not working

exports.createAutoJobs = async (req, res, next) => {
console.log("Request received")
    cron.schedule('00 13 15 * *', () => {
        console.log('Running');
    });
}

The custom pattern is working if it is outside the container as a normal Nodejs application, but not inside the docker container. What is the way to get around it and run the cron jobs inside a docker container. Is there an alternative to this approach?

In my case the problem was the base image. I used node:18-slim . After switching to node:18-alpine the problem was solved. I guess any image except slim will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM