0

I'm newbie using Docker and Python and I'd like some help. I'm trying to run a Python program inside a Docker container. This program needs to run periodically, so my approach was, after cloning and installing my program, to run it as a cron job. I created the Dockerfile with all the steps but it's not working. I tried entering the container to run the application but it shows me this error:

root@84592d72d4f0:/bsnap/bsnap# bsnap
Traceback (most recent call last):
 File "/usr/local/bin/bsnap", line 9, in <module>
 load_entry_point('bsnap==1.1', 'console_scripts', 'bsnap')()
 File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 522, in load_entry_point
 return get_distribution(dist).load_entry_point(group, name)
 File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2647, in load_entry_point
 return ep.load()
 File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2320, in load
 return self.resolve()
 File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2326, in resolve
 module = __import__(self.module_name, fromlist=['__name__'], level=0)
 File "build/bdist.linux-x86_64/egg/bsnap/app.py", line 27, in <module>
 File "build/bdist.linux-x86_64/egg/bsnap/log.py", line 33, in <module>
 File "/usr/local/lib/python2.7/logging/handlers.py", line 760, in __init__
 self._connect_unixsocket(address)
 File "/usr/local/lib/python2.7/logging/handlers.py", line 788, in _connect_unixsocket
 self.socket.connect(address)
 File "/usr/local/lib/python2.7/socket.py", line 224, in meth
 return getattr(self._sock,name)(*args)
socket.error: [Errno 2] No such file or directory

This is my Dockerfile:

FROM ubuntu:14.04
MAINTAINER Dave J. Franco 
RUN echo "deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc) main universe" >> /etc/apt/sources.list
RUN apt-get update && apt-get upgrade -y
#Install container essentials
RUN apt-get install -y tar \
 git \
 curl \
 nano \
 wget \
 dialog \
 net-tools \
 build-essential
# Install pip's dependency: setuptools:
RUN apt-get install -y python python-dev python-distribute python-pip
#git clone project
RUN git clone https://github.com/davejfranco/bsnap.git
#ADD the bsnap configuration file
ADD bsnap.conf /bsnap/bsnap/bsnap.conf
WORKDIR /bsnap
#Install bsnap
RUN python setup.py install
#Add an entry on crontab to execute the script every week 
RUN echo "30 16 09 04 * root /usr/local/bin/bsnap" >> /etc/crontab
Nathaniel Waisbrot
24.7k7 gold badges77 silver badges105 bronze badges
asked Apr 10, 2015 at 13:48
1
  • Could it be related to some address in bsnap.conf? Also cron would not work in this container (and it should not be used in docker in most cases). Commented Apr 10, 2015 at 16:17

1 Answer 1

1

"I created the Docker file with all the steps but it's not working"

No, your Dockerfile is missing a CMD (or ENTRYPOINT) directive, so Docker doesn't know what to run when you start the container.

You could run a command that does nothing, and then wait for cron to do its thing. Or you could write a cron script yourself:

#!/bin/bash
mins=0
while true; do
 if [ $mins -lt 10080 ]; then
 sleep 60
 mins=$[mins+1]
 else
 /bsnap/bsnap/bsnap
 mins=0
 fi
done

Or you could make your Dockerfile say CMD /bsnap/bsnap/bsnap and then use cron in your host machine to run the container every week. That is how I'd do it, and I believe it's the most Docker-ish path.

"this is my Dockerfile"

You should consider using the official Python container, rather than starting from scratch. It makes it clearer that you're using Python 2.7 and it builds faster (because it's downloading, rather than building more things).

"I tried entering in the instance to run the application but it shows me this"

Here's where the error comes from (GitHib link). Bsnap expects /dev/log to exist, but it doesn't on the Docker container. If it does exist on your host and you want to use it, you could pass -v /dev/log:/dev/log to expose it inside the container. Otherwise, you might need to edit the bsnap code to remove the attempt to log that way.

answered Apr 11, 2015 at 4:02
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.