RUN <command>
in Dockerfile
参考:
shell 形式,命令在 shell 中运行,默认情况下在 Linux 上为 /bin/sh -c 或在 Windows 上为 cmd /S /C
让我们看看到底是什么/bin/sh
位于 ubuntu:14.04:
$ docker run -it --rm ubuntu:14.04 bash
root@7bdcaf403396:/# ls -n /bin/sh
lrwxrwxrwx 1 0 0 4 Feb 19 2014 /bin/sh -> dash
/bin/sh 是一个符号链接dash
, see read
函数于dash
:
$ man dash
...
read [-p prompt] [-r] variable [...]
The prompt is printed if the -p option is specified and the standard input is a terminal. Then a line
is read from the standard input. The trailing newline is deleted from the line and the line is split as
described in the section on word splitting above, and the pieces are assigned to the variables in order.
At least one variable must be specified. If there are more pieces than variables, the remaining pieces
(along with the characters in IFS that separated them) are assigned to the last variable. If there are
more variables than pieces, the remaining variables are assigned the null string. The read builtin will
indicate success unless EOF is encountered on input, in which case failure is returned.
By default, unless the -r option is specified, the backslash ``\'' acts as an escape character, causing
the following character to be treated literally. If a backslash is followed by a newline, the backslash
and the newline will be deleted.
...
read
函数于dash
:
必须至少指定一个变量。
让我们来看看read
函数于bash
:
$ man bash
...
read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name...]
If no names are supplied, the line read is assigned to the variable REPLY. The return code is zero,
unless end-of-file is encountered, read times out (in which case the return code is greater than
128), or an invalid file descriptor is supplied as the argument to -u.
...
所以我猜你的剧本myscript.sh
是开始于#!/bin/bash
或其他但不是/bin/sh
.
此外,您还可以更改您的Dockerfile
像下面这样:
FROM ubuntu:14.04
RUN echo yes | read ENV_NAME
Links:
- https://docs.docker.com/engine/reference/builder/
- http://linux.die.net/man/1/dash
- http://linux.die.net/man/1/bash