Skip to content

Replace /etc/profile.d for Environment Variable Persistence in Dockerfiles #1789

Open
@c-ewing

Description

@c-ewing

In the Docker files there are several cases of writing to /etc/profile.d/alicevision.sh as a way of persisting environment variables. Unless I am mistaken these variable's are only used by the build scripts in the Docker images/containers. There is an issue with this however as RUN (in the Dockerfile) and docker run from the command line do not execute login scripts under profile.d. There are several sources for this but this page explains it nicely.

Basically all of the shells launched by Docker are non-login shells, meaning they do not execute login scripts in /etc/profile(.d) unless specifically invoked as a login shell.

I propose rewriting lines such as:

COPY dl/vlfeat_K80L3.SIFT.tree ${AV_INSTALL}/share/aliceVision/
RUN echo "export ALICEVISION_VOCTREE=${AV_INSTALL}/share/aliceVision/vlfeat_K80L3.SIFT.tree" > /etc/profile.d/alicevision.sh

COPY dl/vlfeat_K80L3.SIFT.tree ${AV_INSTALL}/share/aliceVision/
ENV ALICEVISION_VOCTREE=${AV_INSTALL}/share/aliceVision/vlfeat_K80L3.SIFT.tree

This will clarify what the command is doing in the context of the Docker container while also properly persisting environment variable across RUN commands and through the layers in the multistage build.

If the alicevision.sh script is used elsewhere I could not find reference to it but please correct me if I'm wrong.

See #1790

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions