skip to Main Content

For the below "shell" form of RUN instruction, what would be the "exec" form?

RUN echo `uname -rv` > $HOME/kernel-info

I tried below, its giving the error, cat: can't open '/root/kernel-info': No such file or directory

RUN ["echo","uname", "-rv", ">", "$HOME","/kernel-info" ]

2

Answers


  1. To use a different shell, other than /bin/sh, use the exec form passing in the desired shell. For example:

    RUN ["/bin/bash", "-c", "echo hello"]
    
    Login or Signup to reply.
  2. You’re using output redirection and environment variable substitution which are both done by the shell. So you need a shell to run. If you prefer the exec form, you need to run the shell yourself, like this

    RUN [ "/bin/sh", "-c", "echo `uname -rv` > $HOME/kernel-info" ]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search