Search code examples
bashdockerdockerfile

how to reload .bashrc in dockerfile


I am adding many things to the .bashrc in the Dockerfile which is necessary to execute some of the commands I want to run later in the Dockerfile,
I tried source .bashrc which does not work.
I tried using RUN /bin/bash -c --login ... but I get an error : mesg: ttyname failed: inappropriate ioctl for device


Solution

  • Each command in a Dockerfile creates a new temporary container, but without tty (issue 1870, discussed in PR 4955, but closed in favor of PR 4882).

    The lack of tty during docker builds triggers the ttyname failed: inappropriate ioctl for device error message.

    What you can try instead is running a wrapper script which in it will source the .bashrc.

    Dockerfile:

    COPY myscript /path/to/myscript
    RUN /path/to/myscript
    

    myscript:

    #!/bin/bash
    source /path/to/.bashrc
    # rest of the commands    
    

    Abderrahim points out in the comments:

    In my case it was for nvm: it adds an init script to .bashrc therefore it wasn't usable in the Dockerfile context.
    Ended up making an install script with it's dependent command.