修复 Github Actions 中 Docker Compose 中的“恐慌:提供的文件不是控制台”

Ale*_*dru 7 php github docker docker-compose github-actions

概括:

\n

我尝试使用 Github Actions 在 Docker 容器内执行命令,但不断收到以下错误:

\n

恐慌:提供的文件不是控制台

\n

细节

\n

我有一个在 PHP 和 Docker 上运行的 Web 应用程序,我正在使用 Github Action 来构建和部署它。为了安装应用程序的依赖项,我需要composer install从 PHP 容器内运行。过去,此工作流程可以完美运行,但现在开始抛出此错误。

\n

我已经设法消除噪音并将问题减少到本质,但我不知道下一步该怎么做才能解决它。我似乎无法在 PHP 容器内执行任何命令。

\n

我在本地没有任何问题。Github Actions 似乎使用 Docker Compose 版本 2.2.3+azure-1。

\n

我已经尝试通过运行 Nginx 容器... exec nginx date,错误是相同的。

\n

我已经切换到docker-compose而不是docker compose现在我得到了the input device is not a TTY

\n

有人能告诉我出了什么问题吗?

\n

构建工作流.yaml

\n
name: Build application\non:\n  workflow_dispatch:\n    inputs:\n      app_env:\n        description: Environment\n        required: true\n        default: prod\njobs:\n  setup-app:\n    name: Setup application\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n\n      - run: docker compose version\n\n      - run: docker compose --file .docker/docker-compose.local.yml --env-file .docker/.env.local up --build --detach\n\n      - run: docker compose --file .docker/docker-compose.local.yml --env-file .docker/.env.local ps\n\n      - run: docker compose --file .docker/docker-compose.local.yml --env-file .docker/.env.local exec php php --version\n
Run Code Online (Sandbox Code Playgroud)\n

docker-compose.local.yaml

\n
version: "3.9"\n\nservices:\n\n  php:\n    image: php:8.1.1-fpm-alpine\n    volumes:\n      - ../:/var/www/html\n    restart: on-failure:3\n\n
Run Code Online (Sandbox Code Playgroud)\n

Github 操作日志

\n
2022-01-25T21:06:21.0074933Z ##[group]Run docker compose --file .docker/docker-compose.local.yml --env-file .docker/.env.local ps\n2022-01-25T21:06:21.0075489Z [36;1mdocker compose --file .docker/docker-compose.local.yml --env-file .docker/.env.local ps[0m\n2022-01-25T21:06:21.0133835Z shell: /usr/bin/bash -e {0}\n2022-01-25T21:06:21.0134104Z ##[endgroup]\n2022-01-25T21:06:21.1099465Z NAME                COMMAND                  SERVICE             STATUS              PORTS\n2022-01-25T21:06:21.1101562Z cardsman-php-1      "docker-php-entrypoi\xe2\x80\xa6"   php                 running             9000/tcp\n2022-01-25T21:06:21.1160533Z ##[group]Run docker compose --file .docker/docker-compose.local.yml --env-file .docker/.env.local exec php php --version\n2022-01-25T21:06:21.1161074Z [36;1mdocker compose --file .docker/docker-compose.local.yml --env-file .docker/.env.local exec php php --version[0m\n2022-01-25T21:06:21.1218552Z shell: /usr/bin/bash -e {0}\n2022-01-25T21:06:21.1218822Z ##[endgroup]\n2022-01-25T21:06:21.2136074Z panic: provided file is not a console\n2022-01-25T21:06:21.2136423Z \n2022-01-25T21:06:21.2136747Z goroutine 1 [running]:\n2022-01-25T21:06:21.2137132Z github.com/containerd/console.Current(0xc000413a40, 0x0)\n2022-01-25T21:06:21.2137738Z    github.com/containerd/console@v1.0.3/console.go:77 +0xd8\n2022-01-25T21:06:21.2138381Z github.com/docker/compose/v2/cmd/compose.runExec(0x1550860, 0xc00015cf00, 0x15662b8, 0xc000012700, 0xc00000eb80, 0x7ffe99d1c106, 0x3, 0xc00011f870, 0x1, 0x1, ...)\n2022-01-25T21:06:21.2138918Z    github.com/docker/compose/v2/cmd/compose/exec.go:110 +0x4c5\n2022-01-25T21:06:21.2139685Z github.com/docker/compose/v2/cmd/compose.execCommand.func2(0x1550860, 0xc00015cf00, 0xc00011f860, 0x2, 0x2, 0xc000000180, 0x10b8625)\n2022-01-25T21:06:21.2140175Z    github.com/docker/compose/v2/cmd/compose/exec.go:63 +0xd8\n2022-01-25T21:06:21.2140672Z github.com/docker/compose/v2/cmd/compose.Adapt.func1(0x1550860, 0xc00015cf00, 0xc000259680, 0xc00011f860, 0x2, 0x2, 0x12, 0xc00038e460)\n2022-01-25T21:06:21.2141168Z    github.com/docker/compose/v2/cmd/compose/compose.go:85 +0x57\n2022-01-25T21:06:21.2141639Z github.com/docker/compose/v2/cmd/compose.AdaptCmd.func1(0xc000259680, 0xc00011f860, 0x2, 0x2, 0x0, 0x0)\n2022-01-25T21:06:21.2142124Z    github.com/docker/compose/v2/cmd/compose/compose.go:64 +0x13c\n2022-01-25T21:06:21.2215387Z github.com/spf13/cobra.(*Command).execute(0xc000259680, 0xc000129760, 0x2, 0x2, 0xc000259680, 0xc000129760)\n2022-01-25T21:06:21.2215898Z    github.com/spf13/cobra@v1.3.0/command.go:856 +0x472\n2022-01-25T21:06:21.2217020Z github.com/spf13/cobra.(*Command).ExecuteC(0xc000261900, 0xc000261900, 0xc000129700, 0x8)\n2022-01-25T21:06:21.2217477Z    github.com/spf13/cobra@v1.3.0/command.go:974 +0x375\n2022-01-25T21:06:21.2217899Z github.com/spf13/cobra.(*Command).Execute(...)\n2022-01-25T21:06:21.2218305Z    github.com/spf13/cobra@v1.3.0/command.go:902\n2022-01-25T21:06:21.2219295Z github.com/docker/cli/cli-plugins/plugin.RunPlugin(0xc000115930, 0xc0003ad400, 0x1394203, 0x5, 0x139b678, 0xb, 0x1511950, 0xd, 0x0, 0x0, ...)\n2022-01-25T21:06:21.2220708Z    github.com/docker/cli@v20.10.7+incompatible/cli-plugins/plugin/plugin.go:51 +0x146\n2022-01-25T21:06:21.2221338Z github.com/docker/cli/cli-plugins/plugin.Run(0x1410738, 0x1394203, 0x5, 0x139b678, 0xb, 0x1511950, 0xd, 0x0, 0x0, 0x0, ...)\n2022-01-25T21:06:21.2221966Z    github.com/docker/cli@v20.10.7+incompatible/cli-plugins/plugin/plugin.go:64 +0x13f\n2022-01-25T21:06:21.2222318Z main.pluginMain()\n2022-01-25T21:06:21.2222600Z    github.com/docker/compose/v2/cmd/main.go:41 +0xd8\n2022-01-25T21:06:21.2223153Z main.main()\n2022-01-25T21:06:21.2223454Z    github.com/docker/compose/v2/cmd/main.go:74 +0x16c\n2022-01-25T21:06:21.2261798Z ##[error]Process completed with exit code 2.\n2022-01-25T21:06:21.2333072Z Post job cleanup.\n2022-01-25T21:06:21.3833865Z [command]/usr/bin/git version\n2022-01-25T21:06:21.3889002Z git version 2.34.1\n2022-01-25T21:06:21.3935206Z [command]/usr/bin/git config --local --name-only --get-regexp core\\.sshCommand\n2022-01-25T21:06:21.3979636Z [command]/usr/bin/git submodule foreach --recursive git config --local --name-only --get-regexp \'core\\.sshCommand\' && git config --local --unset-all \'core.sshCommand\' || :\n2022-01-25T21:06:21.4329783Z [command]/usr/bin/git config --local --name-only --get-regexp http\\.https\\:\\/\\/github\\.com\\/\\.extraheader\n2022-01-25T21:06:21.4351190Z http.https://github.com/.extraheader\n2022-01-25T21:06:21.4365184Z [command]/usr/bin/git config --local --unset-all http.https://github.com/.extraheader\n2022-01-25T21:06:21.4413547Z [command]/usr/bin/git submodule foreach --recursive git config --local --name-only --get-regexp \'http\\.https\\:\\/\\/github\\.com\\/\\.extraheader\' && git config --local --unset-all \'http.https://github.com/.extraheader\' || :\n
Run Code Online (Sandbox Code Playgroud)\n

在此输入图像描述

\n

Ale*_*dru 13

对于任何试图解决此问题的人,在 Docker Compose版本 2.2.3中,他们删除了对 TTY 的检测。Github Actions 不提供 TTY,因此您需要-T在运行时提供选项docker compose exec

有关实现的更多信息:https://github.com/docker/compose/pull/9035