# Docker Not Exporting Display On Startup

**URL:** <https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303>\
**Category:** Product support\
**Tags:** support, raspberrypi3\
**Created:** [May 14, 2020, 2:29am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303 "2020-05-14T02:29:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![nathv](https://avatars.discourse-cdn.com/v4/letter/n/8baadc/32.png) [@nathv](https://forums.balena.io/u/nathv)\
**Post date:** [May 14, 2020, 2:29am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303/1 "2020-05-14T02:29:52Z")

</div>

Hi there,

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?

---

<div class="post-metadata">

**Author:** ![anujdeshpande](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/anujdeshpande/32/3155_2.png) [@anujdeshpande](https://forums.balena.io/u/anujdeshpande)\
**Post date:** [May 14, 2020, 7:09am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303/3 "2020-05-14T07:09:03Z")

</div>

Hi

Looks like you are trying to set an environment variable. You can do so using environment and service variables - see our docs [here](https://www.balena.io/docs/learn/manage/serv-vars/#fleet-environment-and-service-variables).

Let us know if that works for you

---

<div class="post-metadata">

**Author:** ![nathv](https://avatars.discourse-cdn.com/v4/letter/n/8baadc/32.png) [@nathv](https://forums.balena.io/u/nathv)\
**Post date:** [May 14, 2020, 7:23am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303/5 "2020-05-14T07:23:28Z")

</div>

Is there any reason why this would not work (specifically the export DISPLAY part)?

```
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && export DISPLAY=:1

```

It is in my dockerfile.template file.

---

<div class="post-metadata">

**Author:** ![phil-d-wilson](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/phil-d-wilson/32/3730_2.png) [@phil-d-wilson](https://forums.balena.io/u/phil-d-wilson)\
**Post date:** [May 14, 2020, 7:42am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303/6 "2020-05-14T07:42:53Z")

</div>

Hey Nathaneal

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](https://www.balena.io/docs/learn/more/masterclasses/docker-masterclass/#44-cmd-directive)

Let me know how you get on!  
Phil

---

<div class="post-metadata">

**Author:** ![nathv](https://avatars.discourse-cdn.com/v4/letter/n/8baadc/32.png) [@nathv](https://forums.balena.io/u/nathv)\
**Post date:** [May 14, 2020, 8:56am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303/8 "2020-05-14T08:56:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![phil-d-wilson](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/phil-d-wilson/32/3730_2.png) [@phil-d-wilson](https://forums.balena.io/u/phil-d-wilson)\
**Post date:** [May 14, 2020, 9:03am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303/9 "2020-05-14T09:03:48Z")

</div>

Hi Nathaneal

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?

Phil

---

<div class="post-metadata">

**Author:** ![nathv](https://avatars.discourse-cdn.com/v4/letter/n/8baadc/32.png) [@nathv](https://forums.balena.io/u/nathv)\
**Post date:** [May 14, 2020, 9:07am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303/11 "2020-05-14T09:07:02Z")

</div>

I have this at the end of my Dockerfile.template:

`CMD ["bash", "start.sh"]`

And in my start.sh I have the following at the end:  
`echo "SETTING OUTPUT DISPLAY TO VNC"`  
`export DISPLAY=:1`

But it does not work unfortunately.

---

<div class="post-metadata">

**Author:** ![phil-d-wilson](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/phil-d-wilson/32/3730_2.png) [@phil-d-wilson](https://forums.balena.io/u/phil-d-wilson)\
**Post date:** [May 14, 2020, 9:11am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303/12 "2020-05-14T09:11:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![phil-d-wilson](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/phil-d-wilson/32/3730_2.png) [@phil-d-wilson](https://forums.balena.io/u/phil-d-wilson)\
**Post date:** [May 14, 2020, 9:21am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303/13 "2020-05-14T09:21:11Z")

</div>

Also, I’ve just found a relevant example in our Github, which you can follow:

> **[balena-io-examples/balena-timezone](https://github.com/balena-io-examples/balena-timezone)**
>
> Example to set the timezone on a resin device. Contribute to balena-io-examples/balena-timezone development by creating an account on GitHub.

Maybe that helps you out more?

Phil

---

<div class="post-metadata">

**Author:** ![nathv](https://avatars.discourse-cdn.com/v4/letter/n/8baadc/32.png) [@nathv](https://forums.balena.io/u/nathv)\
**Post date:** [May 14, 2020, 9:27am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303/15 "2020-05-14T09:27:49Z")

</div>

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.

Here’s my Dockerfile.template:

```auto
FROM balenalib/%%BALENA_MACHINE_NAME%%-debian:buster

RUN install_packages x11vnc \
    x11-utils \
    xvfb \
    wmctrl \
    supervisor \
    python3 \
    python3-pip \
    python3-tk \
    python3-setuptools \
    libatlas-base-dev \
    python3-cffi \
    libcairo2 \
    libpango-1.0-0 \
    libpangocairo-1.0-0 \
    libgdk-pixbuf2.0-0 \
    libffi-dev \
    shared-mime-info \
    python3-gi \
    python3-gi-cairo \
    gir1.2-gtk-3.0 \
    python3-cairo \
    python3-matplotlib

ADD /growatt_api_client /growatt_api_client

WORKDIR /app

ADD requirements.txt /app

RUN pip3 install -r requirements.txt

WORKDIR /usr/src/app

COPY . .

ADD supervisor /etc/supervisor

ENV TZ=Australia/Adelaide

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

CMD ["bash", "start.sh"]

```

And here’s my start.sh:

```auto
#!/bin/bash

echo "${TZ}" > /etc/timezone
dpkg-reconfigure tzdata

if [-z ${VNC_PASS}]; then
  echo "STARTING VNC WITHOUT PASSWORD"
  supervisord -c /etc/supervisor/supervisord_np.conf  
else
  echo "STARTING VNC WITH PASSWORD"
  supervisord -c /etc/supervisor/supervisord.conf
fi

echo "SETTING OUTPUT DISPLAY TO VNC"
export DISPLAY=:1 

```

---

<div class="post-metadata">

**Author:** ![phil-d-wilson](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/phil-d-wilson/32/3730_2.png) [@phil-d-wilson](https://forums.balena.io/u/phil-d-wilson)\
**Post date:** [May 14, 2020, 9:51am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303/19 "2020-05-14T09:51:53Z")

</div>

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:

> **[balenalabs/balena-dash](https://github.com/balenalabs/balena-dash)**
>
> Build a Raspberry Pi based desktop dashboard for stats, photos, videos and more! - balenalabs/balena-dash

  
specifically in this file:  

> <https://github.com/balenalabs/balena-dash/blob/master/kiosk/start.sh>

Hope that helps,  
Phil

---

<div class="post-metadata">

**Author:** ![nathv](https://avatars.discourse-cdn.com/v4/letter/n/8baadc/32.png) [@nathv](https://forums.balena.io/u/nathv)\
**Post date:** [May 15, 2020, 1:11am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303/21 "2020-05-15T01:11:53Z")

</div>

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.

```auto
#!/bin/bash

echo "SETTING OUTPUT DISPLAY TO VNC"
export DISPLAY=:1
echo $DISPLAY

echo "${TZ}" > /etc/timezone
dpkg-reconfigure tzdata

```

The `echo`'s do work and in balena console I see `SETTING OUTPUT DISPLAY TO VNC` as well as `:1` for the second `echo`.

 ![image](https://global.discourse-cdn.com/balena/original/2X/8/8a741a0deb385a7c28a688ea6e80f2e6f9675543.png)

But, when the service starts up, the variable is not translated, as seen in this screenshot:

![image](https://global.discourse-cdn.com/balena/original/2X/a/adc812984cf57e0cf351e2edd8d5010503bc11ba.png)

I have to manually export the variable again even though it seems that it is executed on startup. Is there something wrong?

---

<div class="post-metadata">

**Author:** ![karaxuna](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@karaxuna](https://forums.balena.io/u/karaxuna)\
**Post date:** [May 15, 2020, 7:51am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303/26 "2020-05-15T07:51:57Z")

</div>

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](https://askubuntu.com/a/58828) for explanation).

You can set env var with default value in Dockerfile this way:

```auto
ENV Display=:1

```

---

<div class="post-metadata">

**Author:** ![nathv](https://avatars.discourse-cdn.com/v4/letter/n/8baadc/32.png) [@nathv](https://forums.balena.io/u/nathv)\
**Post date:** [May 15, 2020, 8:49am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303/28 "2020-05-15T08:49:05Z")

</div>

I believe I should try the `.bashrc` way however I cannot find the file in the `vnc-app` service. Do I have to create it?

---

<div class="post-metadata">

**Author:** ![odyslam](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/odyslam/32/1684_2.png) [@odyslam](https://forums.balena.io/u/odyslam)\
**Post date:** [May 15, 2020, 9:10am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303/34 "2020-05-15T09:10:13Z")

</div>

Hey,

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.

Best,  
Odysseas

---

<div class="post-metadata">

**Author:** ![nathv](https://avatars.discourse-cdn.com/v4/letter/n/8baadc/32.png) [@nathv](https://forums.balena.io/u/nathv)\
**Post date:** [May 15, 2020, 9:34am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303/35 "2020-05-15T09:34:06Z")

</div>

I tried that with karaxuna’s suggestion but my service still did not start up.

---

<div class="post-metadata">

**Author:** ![odyslam](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/odyslam/32/1684_2.png) [@odyslam](https://forums.balena.io/u/odyslam)\
**Post date:** [May 15, 2020, 10:16am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303/37 "2020-05-15T10:16:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nathv](https://avatars.discourse-cdn.com/v4/letter/n/8baadc/32.png) [@nathv](https://forums.balena.io/u/nathv)\
**Post date:** [May 15, 2020, 10:30am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303/39 "2020-05-15T10:30:25Z")

</div>

Indeed.

![image](https://global.discourse-cdn.com/balena/original/2X/2/2349b5d1f1595e62278ebad7f33b3bce82e007ae.png)

---

<div class="post-metadata">

**Author:** ![CameronDiver](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@CameronDiver](https://forums.balena.io/u/CameronDiver)\
**Post date:** [May 15, 2020, 11:36am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303/40 "2020-05-15T11:36:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nathv](https://avatars.discourse-cdn.com/v4/letter/n/8baadc/32.png) [@nathv](https://forums.balena.io/u/nathv)\
**Post date:** [May 15, 2020, 11:55am UTC](https://forums.balena.io/t/docker-not-exporting-display-on-startup/113303/41 "2020-05-15T11:55:52Z")

</div>

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.
