Better way to view container logs?

If I need to view the logs of a container, I currently either use the web console to access the host OS or balena ssh (ip address) to the device.

Then I have to run balena ps to find the container ID, then run balena logs (container ID) to get the logs.

Is there a simpler / easier way to do this?

Hi @jgentes,

If you are just casually viewing the logs of application containers, you should be able to use the Logs modal on the dashboard. You can additionally filter those logs by message, service, system message, or timestamp.

If you are trying to develop more effectively, you should be able to view logs directly as you build & push code if you use the live push feature. One of our engineers recently wrote a great description of live push and all it’s use cases, you can read more here: https://www.balena.io/blog/living-on-the-edge-with-livepush-and-other-cli-improvements/. There is further documentation here as well: https://www.balena.io/docs/reference/cli/#push-applicationordevice.

Furthermore, if you’d like to tail those logs in your terminal and the container names are predictable, perhaps you could use standard SSH & a tunnel to access them directly (and programmatically). More has been written about tunneling here: Rsync over balena ssh tunnel?.

If you are doing something more with the logs, could you describe a little more about what you are trying to do?

Thanks Matthew, I’m working on static IP configuration, so the environment is a bit difficult to maintain a consistent connection to. I’m using persistent logging to figure out what happened if the device doesn’t come back online after an IP change.

Live push is cool, but it requires local mode, which for some reason seems to airgap the device - it can’t connect to our web service and therefore is hard to troubleshoot as it would behave in a normal environment. So that’s not a super useful option, although I wish it were.

I haven’t looked at the ssh tunnel so that may be interesting. I’ll take a look at that.

I’d like to learn more about your application and how it is conflicting with livepush as this should not be the case and may reflect a bug in livepush itself. How do you typically connect to your webserver?

Hi @xginn8, I just tried local mode again today with the same result - using balenaOS 2.45.1+rev2 with supervisor 10.3.7.

We use websockets to communicate with our server, and as soon as I enable local mode, the server thinks the device has gone offline, although it is online in the balena UI.

Does local mode restrict network access in some way?

Hi,
When enabling local mode, the containers of the release that the device was running stop, and the device starts running the the local mode containers that you push. As a result, your backend sees that the application is stopped, up to the point that the new containers that you push with local mode are built on the device and start running.
Are you still having connectivity issues after the local mode containers start?
Can you clarify whether your application is relying on any environment or service variables to communicate with your backend?

Ah, I didn’t realize that it treats local mode containers differently than what’s already on the device. It does rely on environment variables to identify the IP of the server - Is there a certain way to configure environment vars for local mode?

Hi, adding env vars for local push is not yet supported, but as a workaround you can set env vars in Dockerfile or docker-compose.yml as defaults. When deployed on production, variables from balena dashboard will override default ones. There’s currently issue opened for this feature: https://github.com/balena-io/balena-cli/issues/919