Proper method of using docker run command

Colibri iMX6 512MB IT
Colibri Evaluation Board

Often when I am running my programs through the debugger it is very slow, and the terminal falls behind (I am outputting a lot of printf statements as I am debugging)

So I often open a terminal, cd to my home directory in /home/torizon and run my program from there, because it is faster:

# ./EmeraBlockEnergyBox

I don’t know if this is best practice or not, I guess its not running inside a docker container when I do this, right? What sort of command would you run if you wanted to run your container “properly” from the command line?

I see that there is an image when I do a

# docker image ls

REPOSITORY                                                                                      TAG                 IMAGE ID                                                                         CREATED             SIZE
emerablockenergybox_arm32v7-debian-no-ssh_bullseye_debug_69ac5093-51e4-4f03-8827-ec9f9390dfe3   latest              107484988768                                                                     2 hours ago         96.9MB
canhandler_arm32v7-debian-python3_bullseye_debug_b2997fdb-bcc2-4014-bc57-bc1847a3025c           latest              6d2a2866eaef                                                                     4 hours ago         147MB
can-torizon-sample                                                                              latest              98ffb8c77234                                                                     3 days ago          164MB
torizon/weston                                                                                  2                   33c0dabf2801                                                                     7 weeks ago         305MB
torizon/kiosk-mode-browser                                                                      2                   31de96a2ab85                                                                     5 months ago        510MB
torizon/kiosk-mode-browser                                                                      2.5.0-20211122      31de96a2ab85                                                                     5 months ago        510MB
torizon/weston                                                                                  <none>              a0250110091f                                                                     5 months ago        305MB
portainer/portainer-ce                                                                          2.9.3               49a6a4ef6f63                                                                     5 months ago        216MB

I tried

docker run emerablockenergybox_arm32v7-debian-no-ssh_bullseye_debug_69ac5093-51e4-4f03-8827-ec9f9390dfe3

but I get:

gdbserver: Error disabling address space randomization: Success
/bin/sh: 1: exec: /EmeraBlockEnergyBox/EmeraBlockEnergyBox: not found
During startup program exited with code 127.
Exiting

But I can see the file is there:

colibri-imx6-10866289:~/EmeraBlockEnergyBox$ ls
EmeraBlockEnergyBox

What am I missing? (don’t say “a brain”)

Greetings @leighjboyd,

It looks like you created this container with our VSCode extensions, is that correct?

If that is the case then the extension should be able to produce the corresponding docker run command based off your project configurations.

Just go to your project for this app and press F1, then run Torizon: docker command line. This should produce arguments equivalent to what the extension does when it executes your container.

Best Regards,
Jeremias

Oh!
This is very useful! Thanks.
So, follow up questions abound then…

When I run this on my command line I get

colibri-imx6-10866289:~$ docker run --network 'host' --volume /dev:/dev --volume /home/torizon/logs:/home/torizon/logs --volume /run/udev:/run/udev --volume /tmp:/tmp --volume ContainerVolume:/NewVolume --volume /home/torizon/EmeraBlockEnergyBox:/EmeraBlockEnergyBox:rw --device /dev/spidev3.0:/dev/spidev3.0 --device /dev/colibri-i2c:/dev/colibri-i2c --publish :6502/tcp emerablockenergybox_arm32v7-debian-no-ssh_bullseye_debug_69ac5093-51e4-4f03-8827-ec9f9390dfe3
WARNING: Published ports are discarded when using host network mode
gdbserver: Error disabling address space randomization: Success
Process /EmeraBlockEnergyBox/EmeraBlockEnergyBox created; pid = 10
Listening on port 6502

and there is no output, nor does the program allow me to exit

In what ways can I manage to produce an output (I am using printf at the moment) or stop the program? Is there a torizon tutorial about this sort of thing which I may have missed?

Thanks again,
Leigh

As I said in your other post: Python command "import can" ModuleNotFoundError - #6 by jeremias.tx

You should probably be running the release version of the container rather than the debug version. Also it’d be helpful if you could keep this conversation to just one of these posts so that we stop hopping back and forth like this.

The debug container you’re running here is well designed for remote debugging with VSCode. Invoking it starts your application but also the debugger. If you just want to run your application like how it would run in a production setting then you want to use the “release” variant which just has your application and no debugger. In the extension you should be able to build and deploy the release variant of your application.

Best Regards,
Jeremias

I see that now,
but I still don’t see how to get printf statements to appear, or how to stop the program when running in release mode (assuming these printf statements are not strictly for debugging purposes)

We can keep this docker-related discussion in this question, of course.

If you’re directly printing to stdout then the output should appear in that container’s logs. If you’re running the container detached in the background.

To stop the container, it depends if you’re running the container detached in the background or not. If you are then you can use docker stop otherwise you’ll have to interrupt the console with a usual ctrl + c.

Best Regards,
Jeremias

How do I know if I am running detached in the background or not.
I am just using the Torizon command “export docker command line”

docker run --network ‘host’ --volume /dev:/dev --volume /home/torizon/logs:/home/torizon/logs --volume /run/udev:/run/udev --volume /tmp:/tmp --volume ContainerVolume:/NewVolume --volume /home/torizon/EmeraBlockEnergyBox:/EmeraBlockEnergyBox:rw --device /dev/spidev3.0:/dev/spidev3.0 --device /dev/colibri-i2c:/dev/colibri-i2c --publish :6502/tcp --publish 8080:8080/tcp emerablockenergybox_arm32v7-debian-no-ssh_bullseye_debug_69ac5093-51e4-4f03-8827-ec9f9390dfe3

I don’t know if printf is going to stdout (I assume it does, since I didn’t knowingly pipe it to anything else?) So you’re saying there are logs somewhere I should read? NO OUTPUT TO SCREEN?

So to stop, I would need to open another shell to the board, and look at the running docker processes and do a docker stop from there?

Thanks!

How are you starting your container? Are you having VSCode execute things? Or are you manually running this docker run... command yourself?

If VSCode is the one executing things then the application container should be running in the background being executed as a background process. If you are manually executing you need to add the detached flag as per the Docker documentation: Docker run reference | Docker Documentation

If a container is running in the background then it’s stdout can be viewed via docker logs: docker logs | Docker Documentation

As a simple example of all this just create a fresh new C/C++ project in VSCode. This generates a basic “Hello World” application. It prints “Hello World” to stdout which can be seen in that container’s logs via the method I described above.

If you don’t see your printf messages then it must not be going to stdout.

Best Regards,
Jeremias