Friday, March 1, 2019

Docker returns connection error after being setup as cron job

I have a docker container on ubuntu 16.04 and I want to run a docker command periodically. After checking the command runs successfully from the command line I've setup a crontab with the following:




*/1 * * * * sudo docker run {image-name} python3 /{path-to-scrip}/script.py


This seems to work ok until the script outputs something after which point the crons don't run and it stops docker from working with the following message:



docker: Error response from daemon: connection error: desc = "transport: dial unix /var/run/docker/containerd/docke
r-containerd.sock: connect: connection refused".


I've read that stdout may be the problem and I've tried the following in crontab:




*/1 * * * * sudo docker run {image-name} python3 /{path-to-scrip}/script.py > /home/logs 2>&1


This didn't fix the problem and the logs file remains empty.



This is running on a virtual machine and restarting the instance gets me back to square one where docker runs.



I'm not the most experienced sys admin and suspect I've made a naive mistake, but I don't know how to progress this? What should I have done to setup the cron?




Additional info



I'm not sure if it's relevant, but this is running on a google cloud engine instance and the firewall is set to prohibit all external connections.



Update



After a hunch I've got it running on CentOS7, the cron job worked for a number of hours, but then the script gave an error. The error is something to be expected from the script, but this has lead to the same docker message and cron no longer works.



Further update
From this thread I decided to run docker inspect --format '{{json .State }}' {container id for failed run} - this shows the following:




    {"Status":"running","Running":true,"Paused":false,"Restarting":false,"OOMKilled":false,"Dead":false,"Pid":8204,"ExitCode":0,"Error":"","StartedAt":"2018-01-02T03:1
5:03.016836367Z","FinishedAt":"0001-01-01T00:00:00Z"}


I guess I just need to figure out how to stop the process from running in order to shut the container down.

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...