0

Dockerfile

FROM ubuntu:20.04
RUN apt-get update && \
    apt-get install --no-install-recommends sudo && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists
COPY mybin /mybin
# Add mybin to system wide path
ENV PATH=/mybin:$PATH
$ docker run --rm myimg sudo printenv
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=10adc6c192f4
HOME=/root

want to get

PATH=/mybin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

How to set mybin to system wide PATH in Dockerfile?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
impactaky
  • 53
  • 4

1 Answers1

-1

You can add

RUN echo "PATH=/mybin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
" > /etc/environment

to your dockerfile

Jast38
  • 47
  • 1
  • 4
  • /etc/environment doesn't work. Ref. ``` $docker run --rm ubuntu:20.04 cat /etc/environment PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" ``` – impactaky Jun 05 '21 at 13:00
  • Most paths to running Docker containers don't read `/etc/environment` or other shell dotfiles. – David Maze Jun 05 '21 at 13:38
  • Try `RUN echo "export PATH=/new/path:${PATH}" >> /root/.bashrc` and see if that solves your problem as often the PATH is overwritten by .bashrc – Jast38 Jun 05 '21 at 13:44
  • @Jast38 Ofcourse edit .bashrc is not solution. `docker run --rm myimg sudo printenv` is not called from bash. – impactaky Jun 06 '21 at 04:56