The difference between interactive and non-interactive shells is not noted. Hence, that's why above solutions sometimes seem to work and sometimes not.
bashrc files typically get skipped for non-interactive shells. For instance in Debian, the /etc/bash.bashrc file very clearly states:
# System-wide .bashrc file for interactive bash(1) shells.
# To enable the settings / commands in this file for login shells as well,
# this file has to be sourced in /etc/profile.
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
- A RUNcommand in Dockerfile invokes a non-interactive shell. And the path set byENVwill be taken andbashrcscripts will not run.
- docker run -it <image> /bin/bashinvokes an interactive shell.- bashrcwill be run and could override anything set in- ENV, if the for instance- PATHis not defined in the usual- PATH=$PATH:/...syntax in any of the- bashrcscripts.
In order to be safe and consistent between the 2 modes of operation, one could do in Dockerfile:
ENV PATH /master/go/bin:${PATH}
RUN echo "${PATH}" >> /etc/bash.bashrc
Note that /etc/bash.bashrc is the Debian location and probably is different on other distribution images.