In visual studio code, in my java project repository, I created a Dockerfile with the following content:
FROM rocky-9-wsl2kernel-ni:latest
RUN dnf install -y rpm-build gcc make vim git wget \
openssh-server bc flex bison openssl-devel elfutils-libelf-devel \
rsync kmod ncurses-devel pkg-config chkconfig dwarves java-17-openjdk-devel
EXPOSE 5025
In the vscode command palette, I ran a command that auto created a .devcontainer/devcontainer.json file. I added code to it. The following is the content of my .devcontainer/devcontainer.json file:
{
"name": "Existing Dockerfile",
"build": {
// Sets the run context to one level up instead of the .devcontainer folder.
"context": "..",
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerfile": "../Dockerfile"
},
"runArgs": [
"--net",
"host",
"--env",
"DISPLAY=host.docker.internal:0",
"--privileged",
"--cap-add=ALL"
],
"customizations": {
"vscode": {
"extensions": [
"vscjava.vscode-java-pack",
"ms-azuretools.vscode-docker"
]
}
}
}
In the vscode command palette, I ran the command Dev Containers: Rebuild Without Cache and Reopen in Container. Inside the container built from .devcontainer/devcontainer.json, I ran the following commands sequentially which I got from the guide https://learn.microsoft.com/en-us/community/content/wsl-user-msft-kernel-v6 : cd /usr/src/kernels, git clone https://github.com/microsoft/WSL2-Linux-Kernel.git --depth=1 -b linux-msft-wsl-6.1.y, cd WSL2-Linux-Kernel, make -j$(nproc) KCONFIG_CONFIG=Microsoft/config-wsl, make modules_install headers_install, make defconfig. I then pulled up a windows powershell and ran the command docker cp 90a6f4002eee8c8c2733d70cb997a0817f88471291afa35b3fa05ce6a5ca4277:/usr/src/kernels/WSL2-Linux-Kernel/arch/x86/boot/bzImage /Users/eliam.calvo. In that same windows powershell I ran the command docker commit 90a6f4002eee8c8c2733d70cb997a0817f88471291afa35b3fa05ce6a5ca4277 rocky-9-wsl2kernel:latest next. On my windows machine, I then went to C:\Users\eliam.calvo and created the file .wslconfig with the following content:
[wsl2]
kernel=C:\\Users\\eliam.calvo\\bzImage
I then closed the connection to the dev container and then pulled up a windows powershell as administrator and ran the command wsl --shutdown.
I then changed my Dockerfile to the following:
FROM rocky-9-wsl2kernel:latest
EXPOSE 5025
I then ran the command Dev Containers: Reopen in Container in the vscode command palette. I then ran the command docker cp /Users/eliam.calvo/Desktop/NILinux2024Q1DeviceDrivers/NILinux2024Q1DeviceDrivers/ni-rhel9-drivers-2024Q1.rpm e156acaa0815b2df90aa79a467f2df26775f19d7db67ec50f30f73df54ba86e7:/home in a windows powershell which I got the rpm from https://www.ni.com/en/support/downloads/drivers/download.ni-linux-device-drivers.html#521765. Then, inside the dev container terminal, I ran the following command sequentially which I basically followed from https://www.ni.com/docs/en-US/bundle/ni-platform-on-linux-desktop/page/installing-ni-products-red-hat-enterprise-linux.html : dnf install -y /home/ni-rhel9-drivers-2024Q1.rpm, dnf install -y ni-visa, rm -rf /usr/src/kernels/5.14.0-362.18.1.el9_3.x86_64, dnf install -y ni-hwcfg-utility, and dkms autoinstall. Then, in a windows powershell, I ran the command docker commit e156acaa0815b2df90aa79a467f2df26775f19d7db67ec50f30f73df54ba86e7 rocky-9-wsl2kernel-ni:latest. I then closed the remote connection. I then changed my Dockerfile to the following:
FROM rocky-9-wsl2kernel-ni:latest
EXPOSE 5025
I then opened a dev container in vscode by running the command Dev Containers: Reopen in Container in the vscode command palette. By the way, the .devcontainer/devcontainer.json has remained the same this whole time. Then, in the terminal inside my dev container, I run the command modprobe -v nipalk and insmod /usr/lib/modules/6.1.21.2-microsoft-standard-WSL2+/extra/NiViPciK.ko to insert the required kernel modules in. Inside my Java repository inside the dev container, I run my Java application. When the Java application executes the line JVisaLibrary.viOpenDefaultRM(NativeLongByReference arg0), my application closes abruptly. This is what the terminal inside that docker container looks like:
[root@docker-desktop msda-test]# lsmod
Module Size Used by
NiViPciK 77824 0
nipalk 897024 1 NiViPciK
nikal 102400 1 nipalk
[root@docker-desktop msda-test]# cd /workspaces/msda-test ; /usr/bin/env /usr/lib/jvm/java-17-openjdk-17.0.10.0.7-2.el9.x86_64/bin/java -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:34353 @/tmp/cp_aevhl9otyttw9qr0cmd0fl9ar.argfile com.bluehalo.msda.cca.tester.Tester
libnipalu.so failed to initialize
Verify that nipalk.ko is built and loaded.
Aborted
[root@docker-desktop msda-test]#
As you can see, I check to see if the modules are loaded in yet before running my java application. Then after the application is ran, i get the error from the terminal output above. I’m not sure what else to try.
Turns out that the device node
/dev/nipalkwasn't created automatically. A work around that I did was first do agrep nikal /proc/devicesto find the major device number assigned to the nikal module. Then I did amknod /dev/nipalk c major_number minor_number. Replacemajor_numberwith the number you got from the output ofgrep nikal /proc/devicesandminor_numberwith0, assuming that is the first created device fornikalthat thenikaldriver manages. The following is my terminal output as an example.I don't know why the device wasn't created automatically though whenever I loaded the module into the kernel. Also, I don't know why I have to load in the modules manually either. In a normal installation, all I have to do is follow the steps from https://www.ni.com/docs/en-US/bundle/ni-platform-on-linux-desktop/page/installing-ni-products-red-hat-enterprise-linux.html .