勉強日記

チラ裏

【Laradock】【Windows】workspaceコンテナの操作で "the input device is not a TTY" と怒られるのを回避する方法


環境

現象

  • GitBashやEmacs Shellなどの上で下記コマンドを実行する
docker-compose exec --user=laradock workspace bash
  • 下記エラーが出る
the input device is not a TTY
  • ttyと標準入力をつないでbashで対話しようとしているので、これはまあわかる
    • docker container exec -it-itに相当する部分
  • しかし、ttyと標準入力をつなぐ必要のない操作でも怒られてしまう
docker-compose exec --user=laradock workspace vendor/bin/phpunit
the input device is not a TTY
  • これは回避できる

回避方法

  • そもそもとして、docker-compose.ymlでworkspaceコンテナにはttyフラグが指定されている
    • 指定しないと即EXIT 0してしまう
### Workspace Utilities ##################################
    workspace:
      build:
        context: ./workspace
        args:
          - LARADOCK_PHP_VERSION=${PHP_VERSION}
...          
      ports:
        - "${WORKSPACE_SSH_PORT}:22"
      tty: true
      environment:
...
  • exec時に「tty使わないよ」と明示的に指定してやればよい
docker-compose exec --help
Execute a command in a running container

Usage: exec [options] SERVICE COMMAND [ARGS...]

Options:
    -d                Detached mode: Run command in the background.
    --privileged      Give extended privileges to the process.
    -u, --user USER   Run the command as this user.
    -T                Disable pseudo-tty allocation. By default `docker-compose exec`
                      allocates a TTY.
    --index=index     index of the container if there are multiple
                      instances of a service [default: 1]
  • これ
    -T                Disable pseudo-tty allocation. By default `docker-compose exec`
                      allocates a TTY.
# docker-compose exec --user=laradock workspace vendor/bin/phpunit
docker-compose exec -T --user=laradock workspace vendor/bin/phpunit
  • bashで入れないので不便だが、外からphpunitartisanを実行することはできる

根本的解決方法

  • WindowsをアンインストールしてLinuxをインストールする