Pass Arguments to Applications
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 2. 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.
- Having understood the basics of Torizon IDE Extension 2.
- Toradex System on Module (SoM) with Torizon OS installed.
- Having created a single-container project.
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
- Locate the
.vscodefolder in your project repository.
- Inside the
.vscodefolder, find and open the
- Search for the configuration name associated with the architecture of your target device:
- TorizonV7 for ARM32 devices.
- TorizonV8 for ARM64 devices.
- Modify the
argsvariable by adding your program's arguments. Note that each argument is separated with commas. For example:
As an example, the video below demonstrates these steps for a .NET Core sample:
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
ENTRYPOINTinstruction to configure the container to run as an executable. This is achieved by defining the application as the entry point of the container:
- Add the
CMDinstruction to the Dockerfile. This command defines default arguments for the container entry point:
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>