I have built a GUI application with Tkinter and Python3 and I am trying to display it on a VNC screen. I have followed Balena’s tutorial on VNC application with balena and it works fine. However, I want to export the screen on start up. Everytime I push code to my device, I have to manually execute this code
export DISPLAY=:1
I have tried doing things with the Dockerfile.template, start.sh, and even the supervisor config files but none of these work and I have to continue doing this manually. Is there anyway to resolve this?
The RUN command you have put above is for the dockerfile itself, and so will run on the builder. This command won’t be run on the device itself. To do what you need, you will need to put your command(s) into a bash shell script file, and make the dockerfile run that using the CMD command. There are more details to this here: https://www.balena.io/docs/learn/more/masterclasses/docker-masterclass/#44-cmd-directive
I have tried the CMD function in both start.sh and a separate .sh file but none of these seem to work. I have tried executing an echo "STARTING EXPORT DISPLAY" but that doesn’t seem to execute either. The other commands in these sh files seem to work though. Am I doing something wrong?
Did you manage to take a look at our masterclass linked above? It gives you some good examples of running the CMD directive. This is a docker command so doesn’t run in the bash script, but makes a bash script run on the device itself. If you put your shell commands inside your start.sh and run this file with the CMD directive, you should see the result of your echo in the service logs within balenaCloud. Can you confirm whether you can get that part to work?
Hey - when you say it does not work, do you get the echo output in your device logging in balenaCloud?
Could you send me the contents of your dockerfile in full, and if you are using a docker-compose file send that as well? Just to check nothing is amiss in those.
Update: So having a separate file didn’t do anything either - I don’t know if it executed but the echo did seem to work but the file still failed to open.
Hi - I think it is worth you spending the time going through our Docker Masterclass (linked above) and making sure you understand what each of the commands is doing, and where they are run (i.e. in the builder or in the container). Also, try running the timezone example linked above, and make sure you understand how that example is running. That will give you a good basis for getting your solution to work. Also, we have an example which exports the display, which you can also see how we do it ourselves:
Thank you for the resources Phil. I might switch to using balena-dash as it might be more catered for my needs.
I looked at the start.sh you linked above and I tried to do some things. However, when going through start.sh, it seems to execute that function but the variable is not translated for some reason.
Hi, when you set export Display=:1 it only works for current shell. When you open terminal on dashboard, that’s another instance, that’s why you don’t see previously exported value there (see this answer for explanation).
You can set env var with default value in Dockerfile this way:
The easier route would be to create an environment variable either through Dockerfile or through our Dashboard. This way the environment variable will be always available in the container.
I see in your Dockerfile that you already set an env variable ENV TZ=Australia/Adelaide. Can you verify that you can detect that environment variable when you SSH into the container, by running echo $TZ.
Hey, the variables that you export from your startup script will not be exported to a shell that you open in the container. Your $TZ variable is set because you use an ENV directive in the Dockerfile, and if you use an ENV directive for DISPLAY, it will be set in the container. If you app still doesn’t work after that, I’m fairly sure the env var is not the problem.
I just checked echo $DISPLAY and it seems that :1 is indeed there. But x11vnc keeps exiting so I might just move on to balena dash or Grafana. Thank you for all the support and sorry for any inconvenience.