i am currently making a react application with a backend
i have made page that let me change the date of my machine using a nodejs code,
the command to change the date is : sudo date -s “2024-05-29 15:13:00” as you can see there is a sudo,
i have changed the sudoers file to let everyone change the date of my machine :
Cmnd_Alias DATEE=/bin/date
ALL ALL=NOPASSWD: DATEE
and everything was working fine ,
the thing is : when i am running my application in a container docker , i get the error :
/bin/sh: sudo: not found
if you have any idea on how to modify my docker to make it work.
here is the dockerfile of my application :
FROM docker.io/node:14-alpine as build
WORKDIR /app
COPY package*.json ./
RUN npm install
RUN npm install -g nodemon
COPY . .
COPY get_host_ip.sh /usr/local/bin/get_host_ip.sh
RUN npm prune --production
RUN chmod +x /usr/local/bin/get_host_ip.sh
RUN ls -l /app/start.sh && cat /app/start.sh && chmod +x /app/start.sh
EXPOSE 8080 8000
CMD ["/usr/local/bin/get_host_ip.sh", "sh", "-c", "./start.sh"]
and here is the code of my backend :
exports.UpdateDate = (req, res, next) => {
const payload = req.body;
const date = payload.date;
console.log(date);
const command = `sudo date -s "${date}"`;
exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`Erreur lors de l'exécution de la commande : ${error.message}`);
res.status(500).send("Erreur interne du serveur");
return;
}
if (stderr) {
console.error(`Erreur lors de l'exécution de la commande : ${stderr}`);
res.status(500).send("Erreur interne du serveur");
return;
}
console.log(stdout);
res.send(stdout);
});
;
};
i have tried to build my image using sudo , run it like that but nothing seems to work
gabriel delset is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.