Pass Arguments to Applications
Introduction
This article describes how to pass arguments to applications that run inside containers.
Depending on the development phase of your project, the process of sending arguments to applications varies. When debugging, you have to edit the configuration files created by the Torizon IDE extension. Otherwise, after building an image, arguments are passed through Dockerfile intructions and Docker Run commands.
This article complies with the Typographic Conventions for Torizon Documentation.
Prerequisites
- Having understood the basics of Torizon IDE Extension.
- Toradex System on Module (SoM) with Torizon OS installed.
- Having created a single-container project.
Debugging
When debugging, the Torizon IDE extension manages the creation and running of the debugger container. Also, to facilitate project management, the extension provides various configuration files. Among them, the launch.json
file stores the configurations required to launch the application with the debugger.
To pass command-line arguments to your application, edit the launch.json
file:
- Locate the
.vscode
folder in your project repository. - Inside the
.vscode
folder, find and open thelaunch.json
file. - Search for the configuration name associated with the architecture of your target device:
- TorizonV7 for ARM32 devices.
- TorizonV8 for ARM64 devices.
- Modify the
args
variable by adding your program's arguments. Note that each argument is separated with commas. For example:"args": ["0","5"]
.
As an example, the video below demonstrates these steps for a .NET Core sample:
Runtime
There are multiple methods available for passing command-line arguments to containers. Therefore, we recommend referring to the Dockerfile Reference documentation.
As an example, the steps to pass arguments to a .NET Core sample are as follows:
- In your project repository, locate and open the Dockerfile.
- Add the
ENTRYPOINT
instruction to configure the container to run as an executable. This is achieved by defining the application as the entry point of the container:
ENTRYPOINT ["gpioDotnet"]
- Add the
CMD
instruction to the Dockerfile. This command defines default arguments for the container entry point:
CMD ["0","5"]
When running the container, we can still overwrite default ENTRYPOINT
arguments. The arguments are passed after the container name in the Docker Run command, as shown below:
# docker run --rm -it --device /dev/gpiochip0 <container_name> <arg_1> <arg_2>