运行 docker exec 报错 the input device is not a TTY

在使用 docker in docker 时,在容器内执行命令刷新 nginx:

docker exec -it nginx-nginx-1 nginx -s reload

结果一直报错:

the input device is not a TTY

查阅帮助文档:

madray@pve:/mnt/core/app/nginx/conf.d$ docker exec --help

Usage:  docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

Execute a command in a running container

Aliases:
  docker container exec, docker exec

Options:
  -d, --detach               Detached mode: run command in the background
      --detach-keys string   Override the key sequence for detaching a container
  -e, --env list             Set environment variables
      --env-file list        Read in a file of environment variables
  -i, --interactive          Keep STDIN open even if not attached
      --privileged           Give extended privileges to the command
  -t, --tty                  Allocate a pseudo-TTY
  -u, --user string          Username or UID (format: "[:]")
  -w, --workdir string       Working directory inside the container

显然,-t 参数需要当前环境支持 TTY,而默认情况下容器不支持 TTY,因此将 -t 参数移除即可:

docker exec -i nginx-nginx-1 nginx -s reload