Alpine uses Ash and from the ash(1) man page:
Therefore, a user should place commands to be executed only at login time in the .profile file, and commands that are executed for every shell inside the ENV file.
but, "every shell" isn't correct in the docs because the ENV variable is not read for non-interactive shells. For non-interactive shells, we can set the PATH variable in the Dockerfile:
ENV PATH=/root/.local/bin:$PATH
On the other hand for login shells (/bin/sh --login) setting PATH in the Dockerfile doesn't work because login scripts usually set the PATH variable which overrides whatever was set before. So to make it work for login shells we can add the following into /etc/profile:
RUN echo 'export "PATH=$PATH:my_path"' >> /etc/profile
To sum it up, I just add these two commands into the Dockerfile to update the PATH variable correctly:
ENV PATH=/root/.local/bin:$PATH
RUN echo 'export "PATH=$PATH:my_path"' >> /etc/profile
This works for Ash (/bin/sh), Bash (/bin/bash) and ZSH (/bin/zsh) on Alpine.