Fix "panic: provided file is not a console" from Docker Compose in Github Actions

Viewed 860

Summary:

I'm trying to execute a command inside a Docker container using Github Actions and I keep receiving the following error:

panic: provided file is not a console

Details

I have a web application running on PHP and Docker and I'm using Github Action to build and deploy it. In order to install application's dependencies, I need to run composer install from within the PHP container. In the past, this workflow used to work flawlessly but now it started throwing this error.

I've managed to strip away the noise and reduce the problem to essentials but I don't know what to do next in order to fix it. It seems like I can't execute any commands inside the PHP container.

I don't have any issues on local. Github Actions seem to use Docker Compose version 2.2.3+azure-1.

I've tried with Nginx container by running ... exec nginx date and the error is the same.

I've switched to docker-compose instead of docker compose and now I get the input device is not a TTY.

Can someone tell me what is wrong?

build-workflow.yaml

name: Build application
on:
  workflow_dispatch:
    inputs:
      app_env:
        description: Environment
        required: true
        default: prod
jobs:
  setup-app:
    name: Setup application
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - run: docker compose version

      - run: docker compose --file .docker/docker-compose.local.yml --env-file .docker/.env.local up --build --detach

      - run: docker compose --file .docker/docker-compose.local.yml --env-file .docker/.env.local ps

      - run: docker compose --file .docker/docker-compose.local.yml --env-file .docker/.env.local exec php php --version

docker-compose.local.yaml

version: "3.9"

services:

  php:
    image: php:8.1.1-fpm-alpine
    volumes:
      - ../:/var/www/html
    restart: on-failure:3

Github Action Logs

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

enter image description here

1 Answers

For anyone trying to solve this, in Docker Compose version 2.2.3 they removed detection for TTY. Github Actions does not provide TTY therefore you need to supply -T option when running docker compose exec.

More about the implementation here: https://github.com/docker/compose/pull/9035

Related