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
RUN
command in Dockerfile invokes a non-interactive shell. And the path set by ENV
will be taken and bashrc
scripts will not run.
docker run -it <image> /bin/bash
invokes an interactive shell. bashrc
will be run and could override anything set in ENV
, if the for instance PATH
is not defined in the usual PATH=$PATH:/...
syntax in any of the bashrc
scripts.
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.