I have a simple setup with python’s logging module set up in a python application like so:
app_logger = logging.getLogger('main_thread') file_handler = RotatingFileHandler('/home/pi/FaunderGateway_Log.log', maxBytes=10000000, backupCount=5) formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(name)s - %(message)s') file_handler.setFormatter(formatter) app_logger.addHandler(file_handler)
I have a RotatingFileHandler which has the absolute path “/home/pi/FaunderGateway_Log.log” (this application will be running on a raspberry pi in case anyone’s wondering), now I’m trying to containerize the application with docker.
After building and trying to run my container I get the error:
[Errno 2] No such file or directory: '/home/pi/FaunderGateway_Log.log'
Now, I’m aware that docker has its own file system within the container that is separate from the host’s (pi) file system, but I want to tell docker to let my python app log normally in the host’s absolute path /home/pi/. How can I achieve this?
I read some other threads which mentioned volumes but I don’t really understand them all that well.
I’m using this command to run my container:
sudo docker run --privileged fg
The –privileged flag is so that I can access /dev/mem file on the pi, for GPIO operations.
Update: Please note, that I want my docker container to create the log file in the host’s path “/home/pi”, I don’t want to create a “/home/pi” directory inside the container itself.