How to run a Server in a docker container AND start a Application for debugging

Hello Everyone,

I want to run a DHCP server in a Docker container on an Apalis module and provide a control API.
Dotnet C# would be preferred, but we already have a largely finished solution as a Python app.
I have tried a number of options as to how best to get a default setting, etc.
What was unfortunate was that I couldn’t find a way to debug the Python script and automatically start the DHCP server.
What needs to be done is that when debugging starts, the server starts first and then the Python app including Flask API?

Best regards
Gerald

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello Gerald,

To run a DHCP server and a Python application with a Flask API in a Docker container on your Toradex Apalis module, you can follow these steps:

  1. Docker Container Setup:

    • Create a Dockerfile for your application. This should include both the DHCP server and the Python application. Use a base image that supports Python and any other necessary dependencies.
    • Define the entry point in the Dockerfile to start the DHCP server first, followed by the Python application. You can achieve this by using a shell script that initiates both services in the correct order.
  2. Autorun on Startup:

    • On TorizonCore, configure your Docker container to start automatically on boot. This is done by defining the container in a Docker Compose file and using TorizonCore services to manage it.
    • Ensure your Docker Compose file specifies the correct startup order if there are dependencies between services.
  3. Debugging the Python Application:

    • Use the Torizon IDE extension for Visual Studio Code or another supported IDE to manage the debugging environment for applications running in Docker containers.
    • Configure the launch.json file in your IDE to set up the debugging environment. This file allows you to specify how the debugger should start your application, including any necessary command-line arguments.
    • Ensure the debugger is set to attach to the Python process after the DHCP server has started.
  4. Testing and Validation:

    • Test your setup by running the Docker container manually to ensure both the DHCP server and the Python application start correctly.
    • Use the debugging tools in your IDE to step through the Python application and verify that it behaves as expected.

By following these steps, you can effectively manage the startup and debugging of your applications on a Toradex Apalis module using Docker and TorizonCore. This setup provides a robust development and deployment environment tailored to your needs.

Best regards,
Toradex AI Assistant

Please, also check if these links can help you solve your problem:

Connecting to a TCP server in a Torizon/Docker application.

I will test this

This works for me!

maybe it will help someone:

#!/usr/bin/env bash

service isc-dhcp-server start

if [ $? -ne 0 ]; then
  echo "error"
else
  echo "ok"
  . ${APP_ROOT}/.venv/bin/activate && python3 src/main.py --no-sandbox
fi

exit 0

but not quite in a torizon debug session you work as a torizon user
this does not seem to have the rights to start the dhcp server

when I attach and run service isc-dhcp-server start the server starts
this doesn’t work from the start script

1 Like

Hello @gerko,

Do I understand correctly that this is solved for you now? Or do you still have any open topics related to this thread?