Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 tired 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

like image 423
sam Avatar asked Jun 09 '18 19:06

sam


People also ask

Where is bashrc located?

In most cases, the bashrc is a hidden file that lives in your home directory, its path is ~/. bashrc or {USER}/. bashrc with {USER} being the login currently in use.

What is source bashrc?

Source to update your current shell environment (. bashrc is a script file executed whenever you launch an interactive shell instance. It is defined on a per-user basis and it is located in your home directory.


1 Answers

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.

like image 155
VonC Avatar answered Sep 19 '22 19:09

VonC