6

This is the script in Dockerfile. When I directly get into the docker and run the commands manually it is working fine but why not from the Dockerfile.

Dockerfile:

FROM ubuntu:16.04
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get update
RUN apt-get install -y build-essential libssl-dev
RUN apt-get install -y curl git sudo

RUN curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh -o install_nvm.sh
RUN /bin/sh install_nvm.sh
RUN source ~/.profile

Error:

mesg: ttyname failed: Inappropriate ioctl for device

I have tried few of the solutions found like running it as RUN /bin/sh -c "source ~/.profile" and few more but not solving the issue.

mohan08p
  • 5,002
  • 1
  • 28
  • 36
Tara Prasad Gurung
  • 3,422
  • 6
  • 38
  • 76
  • 1
    What is inside of the `~/.profile`? – Jack Gore Aug 22 '18 at 15:45
  • it has just a command to set env. https://pastebin.com/RpQg58r4 @JackGore – Tara Prasad Gurung Aug 22 '18 at 16:05
  • Possible duplicate of [Using the RUN instruction in a Dockerfile with 'source' does not work](https://stackoverflow.com/questions/20635472/using-the-run-instruction-in-a-dockerfile-with-source-does-not-work) – David Maze Aug 22 '18 at 20:31
  • You should probably just use a [standard node image](https://hub.docker.com/_/node) of the version you need rather than trying to install nvm. Even if you could `RUN . $HOME/.profile` note that it would be a no-op, because that shell environment wouldn’t carry over to future steps. – David Maze Aug 22 '18 at 20:33
  • The solutions in there have not worked for me – Tara Prasad Gurung Aug 23 '18 at 09:39

2 Answers2

1

This is very similar to this question: How to solve 'ttyname failed: Inappropriate ioctl for device' in Vagrant?

In ~/.profile there is a line:

mesg n || true

That is incompatible. In order to fix it, make it conditional upon if tty is available (credit Gogowitsch):

RUN sed -i ~/.profile -e 's/mesg n || true/tty -s \&\& mesg n/g'

This sed command replaces mesg n || true (try it, and ignore if it fails) with tty -s && mesg n, (only try it if it will succeed) which makes the error message go away

jgawrych
  • 3,322
  • 1
  • 28
  • 38
0

Try replacing your command with below command. RUN /bin/bash -c "source ~/.profile"

Bukkasamudram
  • 351
  • 1
  • 2
  • 10