Building Containers
HCC2 applications are deployed using Docker containers. The following sections give a brief overview of this process. For more detailed descriptions of Docker, refer to Docker.com.
Example Dockerfile
In your development environment, run the following command:
cd $HOME/restapi_sample_interface
Edit the file Dockerfile
. Configure this file to accommodate your specific app requirements.
The following Dockerfile
is built for this app example.
# Build stage
FROM qratehcc2sdk.azurecr.io/python:3.12-slim-2024-04-19-debugbuild AS builder-image
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, refer to https://aka.ms/vscode-docker-dotnet-configure-containers
RUN useradd -d /app -M -s /sbin/nologin -u 5678 -U appuser
USER appuser:appuser
FROM base AS slim
# Environment variable needed for read-only filesystem
ENV COMPlus_EnableDiagnostics=0
WORKDIR /app
COPY requirements.txt .
RUN pip3 install -r requirements.txt && pip3 install typing-extensions --upgrade
RUN mkdir classes/ & \
mkdir config/ & \
mkdir lib/ & \
mkdir data/ &
COPY --chown=appuser:appuser *.py ./
COPY --chown=appuser:appuser config/ config/
COPY --chown=appuser:appuser classes/ classes/
COPY --chown=appuser:appuser lib/ lib/
COPY --chown=appuser:appuser data/ data/
COPY --chown=appuser:appuser entry_point.sh .
RUN chmod +x entry_point.sh
USER root:root
RUN install -o appuser -g appuser -d -m 0755 /tmp
RUN install -o appuser -g appuser -d -m 0755 /app/config
USER appuser:appuser
ENTRYPOINT ["./entry_point.sh"]
LABEL org.opencontainers.image.authors="NGRTU Team <ngrtuteam@sensiaglobal.com>" \
org.opencontainers.image.vendor="Sensia Global" \
org.opencontainers.image.url="https://www.sensiaglobal.com/" \
org.opencontainers.image.license="Propietary" \
com.sensiaglobal.image.artifacts.source="sensia-edge-docker-dev"
Creating Images Locally (Docker Desktop)
The Docker build
command is used to build a Docker image. If a filename is not provided, the Dockerfile
for the current path is used:
docker build . -t <<name>>/<<app name>>:<<tag>>
To use an alternative Docker file, enter the following:
docker build . -f <<filename>> -t <<name>>/<<app name>>:<<tag>>
where:
<<app name>>
is your app name (in this example, courseapp). Make sure yours is unique, e.g.,<initials>_<app>_<version>
<<tag>>
is the tag you assign to this container for use in later stages.<<filename>>
is the name of the Docker file. The default is 'Dockerfile'.--no-cache
can be added to the Docker build command to recreate the image several times. It ensures that Docker does not use any cached layers during the build process, and that each build step retrieves the latest versions of dependencies and avoids potential inconsistencies.
Tip
To view a list of local images, enter:
sudo docker image ls
Note
Docker images should also appear on the Docker for Windows images page.
Building From Visual Studio 2022
You can build your Docker image from Windows using Visual Studio if you desire. The prerequisites are:
- Visual Studio
- WSL v2 with Ubuntu
- Docker Desktop
To build a Visual Studio HCC2 application:
-
Build and compile your C# application, testing as required with a Modbus server simulator (to replicate a HCC2) or a physical HCC2 device.
-
Add Docker support to your project OR build your own
Dockerfile
. -
From WSL, navigate to your project folder (in the
/mnt/<<windows path>>
) -
Run the Docker build command as described above.
sudo docker build . -t <<name>>/<<app name>>:<<tag>>
Tip
For best performance, keep your code inside WSL's filesystem instead of in the Windows filesystem as shown above.