-
Notifications
You must be signed in to change notification settings - Fork 2
Containerising an IOC
WSL, or Windows Subsystem for Linux, allows the use of a Linux/GNU environment from a Windows machine.
WLS2 is only available in Windows 11 or Windows 10, Version 1903, Build 18362 or later.
The Windows version of your machine can be checked by pressing Win + R
, typing winver
and pressing Enter.
To install WSL, open a PowerShell or CMD window in Administrator mode, and enter the following:
wsl --install
Note: This method only works if WSL is not installed. If you run wsl --install
and see the WSL help text, please try running wsl --list --online
to see a list of available distros and run wsl --install -d <DistroName>
to install a distro.
If you wish to uninstall the legacy version of WSL, instructions of how can be found here
Further information on the WSL installation process can be found here
Rancher Desktop is an application provides container management and Kubernetes on the desktop. Rancher Desktop provides the ability to build, push, and pull container images along with the ability to run containers.
Rancher Desktop can be installed here.
Once the .exe file has been downloaded, follow the steps to complete the installation process.
Ensure the dockerd
is selected as the runtime during the installation or within the Rancher Desktop settings.
-
Create a folder in which all container file will be stored i.e.
C:\Instrument\App\Epics\Container
. -
Within the folder, create a
test.db
file:record(ao, "TESTTEST:FOO") {}
-
Additionally, a
Dockerfile
should be added as this is the set of 'instructions' from which Docker builds images. Below is an example which creates a container with a simple IOC:FROM python:3.11-slim RUN apt-get update && \ apt-get install -y \ build-essential \ wget \ git \ && rm -rf /var/lib/apt/list/* RUN pip install --upgrade pip RUN pip install epicscorelibs ENV EPICS_BASE=/epics ENV EPICS_HOST_ARCH=linux-x86_64 ENV EPICS_CA_SERVER_PORT 5066 WORKDIR /app COPY . /app ENTRYPOINT ["python", "-m", "epicscorelibs.ioc", "-d", "testdup.db"]
-
To build the container from the
Dockerfile
, cd into the folder within a CMD window and enter:docker build -t <container_name> .
docker build: Tells Docker to create a new image. -t: Specifies a name for the image you're building. <container_name>: The name you're giving to the new image. .: Tells Docker to use the current folder for the build.
-
To run the container, enter the following (replace the path with your own folder location):
docker run --rm -it --net=host -v <path_to_folder>:/usr/src/app <container_name>
docker run: Starts a container. --rm: Deletes the container when done. -it: Lets you interact with the container. --net=host: Uses your computer’s network. -v <path_to_folder>:/usr/src/app: Shares a folder from your computer with the container. <container_name>: The image to use for the container.
After this, the container should be running within the Python Environment within the CMD window.
-
To test if the PV is readable within the container, a EPICS terminal window is needed. For this, open another CMD window and enter:
C:\Instrument\Apps\Epics\config_env.bat
If
Warning: "Identical process variable name on multiple servers"
appears within the EPICS Terminal , enter the following to set the CA address to that of the container:set EPICS_CA_ADDR_LIST=127.0.0.1:5066
-
Now that both terminals are running, the value from the PV can be retrieve by entering the following command into the EPICS terminal:
caget TESTTEST:FOO
To which the response should be
TESTTEST:FOO 0
Addtionally,
caput <PV_name>
can also be used to set the value of the PV.
The following command entered within the EPICS terminal allows users to check for network connections that are being used by a specified port, in this example the port 5066 is being checked:
netstat -a -n -o |findstr 5066
It would appear that both IBEX and the network=host wish to use port 5064, and the container is being blocked whilst the IBEX server is running.
A solution as been found, which is already included within the Dockerfile, where another port has been bound which enables the container's IOC to be communicated with whilst the IBEX server is running. However, it has been found that each IOC will need it's own port, which can lead to issues as the number IOC increases.
In the above example, an approach similar to epics-containers was attempted, however there are a couple of alternative methods that could be explored.
SnowSignal is a possible alternative to UDP communication between localhost and the container. SnowSignal is designed to create a mesh network between instances of the program that will listen for UDP broadcasts received on one node of the network and rebroadcast on all other nodes.
WLS on Windows 11 22H2 and higher introduced 'Mirror mode networking'. This changes WSL to an entirely new networking architecture which has the goal of 'mirroring' the network interfaces that you have on Windows into Linux, to add new networking features and improve compatibility.