question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Docker image rgitzel/mqttwarn additional python functions not working

See original GitHub issue

Hi to everybody,

first of all I want to thank @rgitzel for the usefull and really complete image for mqttwarn. I need to use mqttwarn functionalities in order to feed a carbon (whisper) db from messages subscribed on a mqtt broker for my project.

I’ve included rgitzel image mqttwarn-full as a service within a docker-compose file in order to be used to build up my solution.

The docker-compose.yml file part (regarding your image) is the following:

  mqttwarn-full:
    container_name: mqttwarn
    restart: always
    image: rgitzel/mqttwarn-full
    volumes:
      - '/opt/mqttwarn/conf:/opt/mqttwarn/conf'
      - '/opt/mqttwarn/log/mqttwarn.log:/opt/mqttwarn/mqttwarn.log'
      - '/opt/mqttwarn/functions:/opt/mqttwarn/functions'
    environment:
      USER_ID: '998'    # UID of the docker_user I've created to run the container
      GROUP_ID: '997'   # GID of the docker_user I've created to run the container 

I’ve so create the mqttwarn.ini file within the host folder /opt/mqttwarn/conf and put a custom python function called my_carbon.py within the host folder /opt/mqttwarn/functions. Note: I’ve also set the permission on that folders (and on all the files within it) to the docker_user accordingly to what I’ve defined within the environment variables section of the docker-compose.yml above (UID:998 and GID:997).

As suggested I’ve include in the mqttwarn.ini file above the name of my custom python function. Below the part of the mqttwarn.ini file (in bold the integration I’ve made in order to be able to use the new python function).

; path to file containing self-defined functions for formatmap and datamap
#functions = 'samplefuncs.py'
functions = 'functions/my_carbon.py'
; name the service providers you will be using.
launch  = file, log, carbon, my_carbon

[config:my_carbon]
targets = {
        'c1' : [ 'graphite_statsd', 2003 ],
  }

[APA0/iIPdubgSRi/#]
targets = my_carbon:c1, log:debug, log:error

When I ran the docker-compose I get the following error in the log of mqttwarn:

2020-05-03 13:25:06,211 INFO  [mqttwarn] Starting mqttwarn
2020-05-03 13:25:06,211 INFO  [mqttwarn] Log level is DEBUG
2020-05-03 13:25:06,216 DEBUG [mqttwarn] Service file loaded
2020-05-03 13:25:06,217 DEBUG [mqttwarn] Service log loaded
2020-05-03 13:25:06,218 DEBUG [mqttwarn] Service carbon loaded
2020-05-03 13:25:06,218 ERROR [mqttwarn] Can't load my_carbon service (services/my_carbon.py): [Errno 2] No such file or directory: u'services/my_carbon.py'

It seems to me that the mqttwarn.py process is searching for the my_carbon.py function file within the default python function folder (that is called services and that is within the container)
instead of searching it within the functions folder that I’ve crated in the host system and where I’ve put the my_carbon.py file.

I’m also sure that the bind mount of the volume I’ve defined within the docker-compose.yml file with the command below:

- '/opt/mqttwarn/functions:/opt/mqttwarn/functions'

I’m sure is working correctly because I can “see” the content of this folder either from the container (entering with exec command) and from the host system…

I’m literally going crazy in order to understand how can I solve it… Can someone please help me in some way?

Thanks a lot in advanced for any help you should give me!!

Leonardo

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:21 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
uilton-oliveiracommented, Sep 23, 2020

I’m using an custom function with cron, and at least on windows host it worked fine here…

Here is my docker-compose:

    mqttwarn:
        image: jpmens/mqttwarn
        container_name: mqttwarn
        restart: unless-stopped
        depends_on:
            - "mqtt"
        volumes:
            - ./mqttwarn:/etc/mqttwarn
        networks:
            - infranet
1reaction
jpmenscommented, May 10, 2020

Apologies, and thanks for reminding me, @koenvervloesem. I have pushed 0.15.1-1 to the hub.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debugging ImportError and ModuleNotFoundErrors in your ...
Your code runs fine on your computer, but when you try to package it with Docker you keep getting ImportError s or ModuleNotFoundError ......
Read more >
Python app does not print anything when running detached in ...
Finally I found a solution to see Python output when running daemonized in Docker, thanks to @ahmetalpbalkan over at GitHub. Answering it here...
Read more >
Build your Python image - Docker Documentation
Learn how to build your first Docker image by writing a Dockerfile. ... Download Python; Docker running locally. Follow the instructions to download...
Read more >
Best practices for containerizing Python applications with Docker
But it creates another problem: you'd be adding all the system-level dependencies from the image we used for compiling the dependencies to the ......
Read more >
Deploy Python Lambda functions with container images
These base images are preloaded with a language runtime and other components that are required to run the image on Lambda. AWS provides...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found