diff --git a/docs/en/api-guides/tools/idf-docker-image.rst b/docs/en/api-guides/tools/idf-docker-image.rst index 988e52d8cb..7295d374f4 100644 --- a/docs/en/api-guides/tools/idf-docker-image.rst +++ b/docs/en/api-guides/tools/idf-docker-image.rst @@ -60,6 +60,10 @@ The above command explained: - ``espressif/idf``: uses Docker image ``espressif/idf`` with tag ``latest`` (implicitly added by Docker when no tag is specified) - ``idf.py build``: runs this command inside the container +.. note:: + + When the mounted directory, ``/project``, contains a git repository owned by a different user (``UID``) than the one running the Docker container, git commands executed within ``/project`` might fail, displaying an error message ``fatal: detected dubious ownership in repository at '/project'``. To resolve this issue, you can designate the ``/project`` directory as safe by setting the IDF_GIT_SAFE_DIR environment variable during the Docker container startup. For instance, you can achieve this by including ``-e IDF_GIT_SAFE_DIR='/project'`` as a parameter. Additionally, multiple directories can be specified by using a ``:`` separator. To entirely disable this git security check, ``*`` can be used. + To build with a specific docker image tag, specify it as ``espressif/idf:TAG``, for example:: docker run --rm -v $PWD:/project -w /project espressif/idf:release-v4.4 idf.py build diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh index 7cf15f1917..513b3ba00d 100755 --- a/tools/docker/entrypoint.sh +++ b/tools/docker/entrypoint.sh @@ -1,6 +1,20 @@ #!/usr/bin/env bash set -e +# IDF_GIT_SAFE_DIR has the same format as system PATH environment variable. +# All path specified in IDF_GIT_SAFE_DIR will be added to user's +# global git config as safe.directory paths. For more information +# see git-config manual page. +if [ -n "${IDF_GIT_SAFE_DIR+x}" ] +then + echo "Adding following directories into git's safe.directory" + echo "$IDF_GIT_SAFE_DIR" | tr ':' '\n' | while read -r dir + do + git config --global --add safe.directory "$dir" + echo " $dir" + done +fi + . $IDF_PATH/export.sh exec "$@"