ESP-IDF Docker: Keep env variables from entrypoint

uzer123
Posts: 12
Joined: Thu May 07, 2020 4:42 pm

ESP-IDF Docker: Keep env variables from entrypoint

Postby uzer123 » Sat Mar 04, 2023 5:01 pm

I’ve searched for long, and i found it strange i cannot find a solution.
I create a docker container like this:
docker run -dit --name test -w /project espressif/idf bash
Then i try to build my app like:
docker exec -it test idf.py build
but idf.py is not recognized.
If i rerun the entrypoint, everything is fine but it takes some extra seconds everytime i do a build:
docker exec -dit test /opt/esp/entrypoint.sh idf.py build

But if i do:
docker run -it --name test -w /project espressif/idf bash
and do:
idf.py build
many times, I have the entrypoint variables working fine.

So, my question is: can i use the terminal that is create at my first run command every time and keeping in this way my variables:
docker run -dit --name test -w /project espressif/idf bash

Alternative Solution: Can i set only some paths and never run the export.sh file?

sidwarkd
Posts: 9
Joined: Mon Aug 02, 2021 9:34 pm

Re: ESP-IDF Docker: Keep env variables from entrypoint

Postby sidwarkd » Sat Mar 04, 2023 9:58 pm

If you just want to build you should be able to use the command as described in the image documentation:

Code: Select all

docker run --rm -v $PWD:/project -w /project espressif/idf:latest idf.py build
When you do exec you are not running in the same context where the entrypoint script executed on your docker "run" which exported all of the env variables for idf.py build. That's why that doesn't work. So you either have to do it the way you are or use docker run for every command you want to execute individually.

You mount in your source and it will be built. If you want to do full development in a docker container (I personally love this approach) with IDF I recommend something like VSCode that has a full dev integration with Docker via Dev Containers.

uzer123
Posts: 12
Joined: Thu May 07, 2020 4:42 pm

Re: ESP-IDF Docker: Keep env variables from entrypoint

Postby uzer123 » Sun Mar 05, 2023 8:16 pm

When you do exec you are not running in the same context where the entrypoint script executed on your docker "run" which exported all of the env variables for idf.py build. That's why that doesn't work. So you either have to do it the way you are or use docker run for every command you want to execute individually.
That's true. It took me sometime to understand how the entrypoint script works in esp-idf containers.
The best solution i found is to `docker run -dit --name something --rm -v $PWD:/project -w /project espressif/idf:latest`
and then whenever i want to build i do `docker attach something` do my `idf.py build` stuff, and press the escape buttons to go back to my host.

Who is online

Users browsing this forum: No registered users and 106 guests