Closed aesculus closed 1 year ago
Hi Chris, there appears to be something off in how you are creating or running the container. Docker namespaces the network too so it will need to plumb the access between the container and influxdb.
Can you share your Dockerfile you use to create the container, and details on how you are running it (e.g. script or docker compose)?
Are you added the new container to the powerwall.yml?
Hi @jasonacox Thanks for the speedy reply. While I might/probably will add it to the powerwall.yml later, right not I am just trying to get it to run stand alone. Maybe that is a bad assumption the way its constructed.
The container app works great when it's not a container. Connects to influxdb and writes to the db just fine. But when I create it as a container and run it, everything works OK until I try to write the data to the powerwall db. Then it times out.
So I created a simple test case that just tries to ping the Influx server. It too works great when run under the shell but times out the same when built and run as a container in Docker.
Here is my test script (note the app uses asynicio instead of threads but I tested without that too and failed):
#!/usr/bin/env python
# LennoxS30 - Current Lennox S30 Conditions
# -*- coding: utf-8 -*-
import asyncio
from influxdb_client.client.influxdb_client_async import InfluxDBClientAsync
async def main():
async with InfluxDBClientAsync(url="http://192.168.1.108:8086", token="my-token", org="my-org") as client:
ready = await client.ping()
print(f"InfluxDB: {ready}")
if __name__ == "__main__":
asyncio.run(main())
And I build it with:
docker build -t lennoxs30:latest .
And then make a container and run it with:
docker run \
-d \
-e LENNOXS30CONF='lennoxs30.conf' \
--name lennoxs30 \
--restart unless-stopped \
lennoxs30
And the Docker file:
FROM python:3.10-alpine
WORKDIR /app
RUN pip3 install requests influxdb-client aiohttp aiocsv lennoxs30api pytz
COPY lennoxs30.conf lennoxs30.conf
COPY server.py server.py
CMD ["python3", "server.py"]
I see the issue. Your docker run
is not putting the container in host mode so it will not be able to hit your private IP address endpoint (http://192.168.1.108:8086)
You should be able to so something like this:
docker run \
-d \
-e LENNOXS30CONF='lennoxs30.conf' \
--name lennoxs30 \
--restart unless-stopped \
--net=host \
lennoxs30
Before you mention it, I see that the weather411 example omits this too, so TO-DO here to update that. 😁
Nailed it.
I cannot tell you how many hours I spent on the net about this. And this is not a totally unique problem. Could not find any real fixes and not one mentioned this at all. That was surprising given how obvious it was after the fact.
Chalk this up to my total unfamiliarity with Docker and just following your lead with the Weather sample and hacking away at it via trial and error. So in the end we fixed a small oversight so the day can be considered a success.
@jasonacox Sorry for a unrelated issue but thought you might have some insight. I am using the weather server example to create another dataset into the powerwall db with a Docker container. All works well with the script running in a shell.
But when I build a Docker container I am having a issue during the write where it times out.
I have tried different versions of the pip install influxdb-client thinking it could have been something new that was introduced recently but no changes.
Any thoughts or ideas to try?