# Enable GPU on Container

**URL:** <https://forums.balena.io/t/enable-gpu-on-container/194366>\
**Category:** balenaOS\
**Tags:** docker, nvidia\
**Created:** [September 28, 2020, 9:06pm UTC](https://forums.balena.io/t/enable-gpu-on-container/194366 "2020-09-28T21:06:11Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![robertgzr](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/robertgzr/32/1387_2.png) [@robertgzr](https://forums.balena.io/u/robertgzr)\
**Post date:** [October 21, 2020, 12:08pm UTC](https://forums.balena.io/t/enable-gpu-on-container/194366/139 "2020-10-21T12:08:37Z")

</div>

probably [2.45.0](https://github.com/balena-os/balena-intel/blob/master/CHANGELOG.md#v2450rev1)

---

<div class="post-metadata">

**Author:** ![robertgzr](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/robertgzr/32/1387_2.png) [@robertgzr](https://forums.balena.io/u/robertgzr)\
**Post date:** [October 21, 2020, 12:11pm UTC](https://forums.balena.io/t/enable-gpu-on-container/194366/140 "2020-10-21T12:11:05Z")

</div>

you are using the same base-image and all as back then on the newer os?

---

<div class="post-metadata">

**Author:** ![scarlyon](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@scarlyon](https://forums.balena.io/u/scarlyon)\
**Post date:** [October 21, 2020, 12:21pm UTC](https://forums.balena.io/t/enable-gpu-on-container/194366/142 "2020-10-21T12:21:34Z")

</div>

Yeah, intel-nuc

---

<div class="post-metadata">

**Author:** ![robertgzr](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/robertgzr/32/1387_2.png) [@robertgzr](https://forums.balena.io/u/robertgzr)\
**Post date:** [October 21, 2020, 12:52pm UTC](https://forums.balena.io/t/enable-gpu-on-container/194366/143 "2020-10-21T12:52:03Z")

</div>

I mean the distro part 🙂

---

<div class="post-metadata">

**Author:** ![scarlyon](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@scarlyon](https://forums.balena.io/u/scarlyon)\
**Post date:** [October 21, 2020, 1:03pm UTC](https://forums.balena.io/t/enable-gpu-on-container/194366/144 "2020-10-21T13:03:43Z")

</div>

> [@Enable GPU on Container](https://forums.balena.io/t/enable-gpu-on-container/194366):
>
> We have been using this approach to install nvidia drivers inside the containers - [NVIDIA drivers on Intel Nuc](https://forums.balena.io/t/nvidia-drivers-on-intel-nuc/2903) But current HOST OS version(balenaOS 2.50.1+rev1) doesn’t seem to support nvidia-driver-435 any more. FROM balenalib/%%BALENA\_MACHINE\_NAME%%-ubuntu-python:3.6-bionic-build ENV RESINOS\_VERSION=2.50.1%2Brev1.prod ENV DEBIAN\_FRONTEND=noninteractive ENV YOCTO\_VERSION=5.2.10 RUN wget https://files.resin.io/images/intel-nuc/${RESINOS\_VERSION}/kernel\_modules\_headers.tar.gz RUN tar -xf kern…

Nothing changed, mate.

---

<div class="post-metadata">

**Author:** ![pdcastro](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/pdcastro/32/1264_2.png) [@pdcastro](https://forums.balena.io/u/pdcastro)\
**Post date:** [October 21, 2020, 9:58pm UTC](https://forums.balena.io/t/enable-gpu-on-container/194366/148 "2020-10-21T21:58:55Z")

</div>

So, the `nvidia-smi` command was working after `RUN apt-get install -y nvidia-driver-435` with the latest balenaOS version in November 2019, but is no longer working with balenaOS `v2.50.1+rev1`. And the hardware last year was an Intel NUC, right? For the Intel NUC, these balenaOS versions would be candidates:

- `v2.45.0+rev4` - released on 19 Nov 2019
- `v2.45.0+rev3` - released on 13 Nov 2019
- `v2.45.0+rev2` - released on 6 Nov 2019
- `v2.45.0+rev1` - released on 1 Nov 2019
- `v2.44.0+rev1` - released 3 Oct 2019

To be sure that nothing else has changed, you could try flashing one of these releases and confirm that the driver works. Also, could the Intel NUC hardware have changed? The NUC has had 10 generations, each with changes to the GPU chipset: [https://en.wikipedia.org/wiki/Next\_Unit\_of\_Computing](https://en.wikipedia.org/wiki/Next_Unit_of_Computing)

---

<div class="post-metadata">

**Author:** ![scarlyon](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@scarlyon](https://forums.balena.io/u/scarlyon)\
**Post date:** [October 21, 2020, 10:02pm UTC](https://forums.balena.io/t/enable-gpu-on-container/194366/149 "2020-10-21T22:02:51Z")

</div>

The hardware device is not changed.

---

<div class="post-metadata">

**Author:** ![pdcastro](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/pdcastro/32/1264_2.png) [@pdcastro](https://forums.balena.io/u/pdcastro)\
**Post date:** [October 21, 2020, 11:22pm UTC](https://forums.balena.io/t/enable-gpu-on-container/194366/150 "2020-10-21T23:22:24Z")

</div>

At risk of suggesting something you have already tried, I’ve noticed that the following command does not include the `--privileged` flag:

```auto
root@balena:~# balena run --gpus all nvidia/cuda:10.2-cudnn7-devel nvidia-smi
balena: Error response from daemon: could not select device driver "" with capabilities: [[gpu]].
ERRO[2020-10-06T02:09:24.698529715Z] error waiting for container: context canceled 

```

Does it make a difference if you add `--privileged`?

---

<div class="post-metadata">

**Author:** ![scarlyon](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@scarlyon](https://forums.balena.io/u/scarlyon)\
**Post date:** [October 22, 2020, 5:26am UTC](https://forums.balena.io/t/enable-gpu-on-container/194366/153 "2020-10-22T05:26:42Z")

</div>

@pdcastro

Hmm, I didn’t use `--privileged` at that time. Will do in the next testing.

By the way, where can I download the old version? 2.45.0+rev1, for instance?

Cheers,  
Shane.

---

<div class="post-metadata">

**Author:** ![scarlyon](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@scarlyon](https://forums.balena.io/u/scarlyon)\
**Post date:** [October 22, 2020, 8:28am UTC](https://forums.balena.io/t/enable-gpu-on-container/194366/154 "2020-10-22T08:28:26Z")

</div>

Any idea how to download the images of such versions?

> [@Previous IMG versions](https://forums.balena.io/t/previous-img-versions/180386/9):
>
> I have a similar issue: anydeskpc@anydeskpc:~$ balena os versions intel-nuc v2.48.0+rev3.prod (recommended) v2.48.0+rev3.dev v2.47.1+rev1.prod v2.47.1+rev1.dev v2.47.0+rev1.prod v2.47.0+rev1.dev v2.46.0+rev1.prod v2.46.0+rev1.dev v2.45.1+rev2.prod v2.45.1+rev2.dev v2.41.1+rev1.prod v2.41.1+rev1.dev v2.39.0+rev3.prod v2.39.0+rev3.dev v2.39.0+rev2.prod v2.39.0+rev2.dev bla bla bla And then: anydeskpc@anydeskpc:~$ balena os download intel-nuc --version v2.45.1+rev2.dev -o balena-intel-nuc-v2.45.…

---

<div class="post-metadata">

**Author:** ![scarlyon](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@scarlyon](https://forums.balena.io/u/scarlyon)\
**Post date:** [October 22, 2020, 10:00am UTC](https://forums.balena.io/t/enable-gpu-on-container/194366/155 "2020-10-22T10:00:18Z")

</div>

Nevermind, my balena-cli was logged in to my openbalena server! 😂

---

<div class="post-metadata">

**Author:** ![vipulgupta2048](https://avatars.discourse-cdn.com/v4/letter/v/a183cd/32.png) [@vipulgupta2048](https://forums.balena.io/u/vipulgupta2048)\
**Post date:** [October 22, 2020, 10:06am UTC](https://forums.balena.io/t/enable-gpu-on-container/194366/157 "2020-10-22T10:06:27Z")

</div>

Let us know what happens after you added the `--privelleged` flag.

---

<div class="post-metadata">

**Author:** ![scarlyon](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@scarlyon](https://forums.balena.io/u/scarlyon)\
**Post date:** [October 23, 2020, 12:45am UTC](https://forums.balena.io/t/enable-gpu-on-container/194366/160 "2020-10-23T00:45:41Z")

</div>

I was using `v2.44.0+rev1` in the last year. But I cannot download now?

```auto
anydeskpc@anydeskpc:~balena os versions intel-nuc
v2.50.1+rev1.prod (recommended)
v2.50.1+rev1.dev
v2.48.0+rev3.prod
v2.48.0+rev3.dev
v2.47.1+rev1.prod
v2.47.1+rev1.dev
v2.47.0+rev1.prod
v2.47.0+rev1.dev
v2.46.0+rev1.prod
v2.46.0+rev1.dev
v2.45.1+rev2.prod
v2.45.1+rev2.dev
v2.41.1+rev1.prod
v2.41.1+rev1.dev
v2.38.3+rev5.prod
v2.38.3+rev5.dev
... ... ...

```

---

<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:** [October 23, 2020, 5:01am UTC](https://forums.balena.io/t/enable-gpu-on-container/194366/161 "2020-10-23T05:01:20Z")

</div>

Hi

The reason you are seeing this is that we had to pull the 2.44 version of the OS for all device types as we found a race condition in the boot process that would sometimes not allow the supervisor to start up correctly.  
See a similar forum issue here - [Can't update from 2.41.1 to 2.44.1](https://forums.balena.io/t/cant-update-from-2-41-1-to-2-44-1/47810/2)  
2.45.1 should work just like 2.44 for you, without the bug

---

<div class="post-metadata">

**Author:** ![scarlyon](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@scarlyon](https://forums.balena.io/u/scarlyon)\
**Post date:** [October 23, 2020, 5:20am UTC](https://forums.balena.io/t/enable-gpu-on-container/194366/164 "2020-10-23T05:20:42Z")

</div>

Ok, **v2.45.1+rev2** is not working…

```auto
root@balena:/# printenv | grep BALENA
BALENA_SUPERVISOR_VERSION=10.3.7
BALENA_DEVICE_TYPE=intel-nuc
BALENA=1
BALENA_SUPERVISOR_HOST=127.0.0.1
BALENA_SERVICE_NAME=od
BALENA_APP_NAME=localapp
BALENA_APP_ID=1
BALENA_DEVICE_UUID=e01f87419ce9c55149a945473533f5fe
BALENA_SERVICE_HANDOVER_COMPLETE_PATH=/tmp/balena/handover-complete
BALENA_SUPERVISOR_ADDRESS=http://127.0.0.1:48484
BALENA_HOST_OS_VERSION=balenaOS 2.45.1+rev2
BALENA_SUPERVISOR_PORT=48484
BALENA_DEVICE_NAME_AT_INIT=local
BALENA_SUPERVISOR_API_KEY=98a0e59477fa38423febee29e23b8fac8b6d0ef8bbfe48d37d7924b1be3fda
BALENA_APP_LOCK_PATH=/tmp/balena/updates.lock
root@balena:/# nvidia-smi i
NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.

```

What should I do? @pdcastro @robertgzr

---

<div class="post-metadata">

**Author:** ![alexgg](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@alexgg](https://forums.balena.io/u/alexgg)\
**Post date:** [October 23, 2020, 2:34pm UTC](https://forums.balena.io/t/enable-gpu-on-container/194366/169 "2020-10-23T14:34:59Z")

</div>

Hi, just re-reading this thread. It seems the problem boils down to the nvidia driver not being present. Could you please let us know how you had installed the driver in the past?

What might be happening is that you installed it from a pre-built distribution like Debian that happened to be compatible with the kernel BalenaOS was running. That was just a coincidence as the BalenaOS kernel releases are not in sync with any distribution.

There are several alternatives:

1. If you have access to the kernel driver source you can build it for a specific BalenaOS version and install it from your application container. You can use the following example project to achieve this [https://github.com/balena-os/kernel-module-build](https://github.com/balena-os/kernel-module-build)

2. We are working on a mechanism that will allow us to release drivers and system libraries with the OS in a more dynamic way, and once it’s ready we will release an OS extension with compatible drivers. I have created an issue so track this work. [https://github.com/balena-os/balena-intel/issues/334](https://github.com/balena-os/balena-intel/issues/334)

---

<div class="post-metadata">

**Author:** ![scarlyon](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@scarlyon](https://forums.balena.io/u/scarlyon)\
**Post date:** [October 26, 2020, 5:58am UTC](https://forums.balena.io/t/enable-gpu-on-container/194366/171 "2020-10-26T05:58:06Z")

</div>

Hi, @alexgg

Sorry for the delay.

Yeah, just installed balenaOS 2.44+rev2(intel-nuc), which is not available at the moment.  
And used the above `Dockerfile.template` to install nvidia driver and CUDA/CUDDN on it.  
`nvidia-smi` worked well and we were able to use the GPU without any issue.

Regarding the alternatives, I don’t think it’s worth building the custom kernel.  
When would you be able to release the new OS extension with GPU support? Any rough estimation?

Cheers,  
Shane.

---

<div class="post-metadata">

**Author:** ![scarlyon](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@scarlyon](https://forums.balena.io/u/scarlyon)\
**Post date:** [November 5, 2020, 10:56am UTC](https://forums.balena.io/t/enable-gpu-on-container/194366/175 "2020-11-05T10:56:45Z")

</div>

Hi, @alexgg  
Any update here?

I can see some signs of progress in the meta-balena project?

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

Cheers,  
Shane.

---

<div class="post-metadata">

**Author:** ![alexgg](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@alexgg](https://forums.balena.io/u/alexgg)\
**Post date:** [November 9, 2020, 10:18am UTC](https://forums.balena.io/t/enable-gpu-on-container/194366/176 "2020-11-09T10:18:23Z")

</div>

Hi Shane, as you say the OS changes have been merged. We are now working on complementary changes on other parts of the product, like the supervisor and our build infrastructure. Once it’s ready we will do a proper write-up along with instructions and documentation.

---

<div class="post-metadata">

**Author:** ![eeb](https://avatars.discourse-cdn.com/v4/letter/e/65b543/32.png) [@eeb](https://forums.balena.io/u/eeb)\
**Post date:** [January 20, 2021, 2:38pm UTC](https://forums.balena.io/t/enable-gpu-on-container/194366/178 "2021-01-20T14:38:57Z")

</div>

Hi @alexgg,

Is there a timeline for this?

Regards,

[Previous page](https://forums.balena.io/t/enable-gpu-on-container/194366.md?page=3)
