How to run Symfony console command inside the docker container
Asked Answered
M

1

6

I am trying to run Symfony 3 console command inside of my docker container but not able to getting proper output.

docker-compose.yaml

version: '3.4'

services:
  app:
    build:
      context: .
      target: symfony_docker_php
      args:
        SYMFONY_VERSION: ${SYMFONY_VERSION:-}
        STABILITY: ${STABILITY:-stable}
    volumes:
      # Comment out the next line in production
      - ./:/srv/app:rw,cached
      # If you develop on Linux, comment out the following volumes to just use bind-mounted project directory from host
      - /srv/app/var/
      - /srv/app/var/cache/
      - /srv/app/var/logs/
      - /srv/app/var/sessions/
    environment:
      - SYMFONY_VERSION

  nginx:
    build:
      context: .
      target: symfony_docker_nginx
    depends_on:
      - app
    volumes:
      # Comment out the next line in production
      - ./docker/nginx/conf.d:/etc/nginx/conf.d:ro
      - ./public:/srv/app/public:ro
    ports:
      - '80:80'

My console command docker-compose exec nginx php bin/console

It returns the following response the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'

Mangrove answered 27/8, 2019 at 12:12 Comment(0)
S
1

Copy from https://docs.docker.com/compose/reference/exec/

To disable this behavior, you can either the -T flag to disable pseudo-tty allocation.

docker-compose exec -T nginx <command>

Or, set COMPOSE_INTERACTIVE_NO_CLI value as 1

export COMPOSE_INTERACTIVE_NO_CLI=1

For php bin/console to run you need to run from app container like below.

docker-compose exec -T app php bin/console

Sequestered answered 27/8, 2019 at 12:20 Comment(7)
I set COMPOSE_INTERACTIVE_NO_CLI value as 1 and try again with your reference command, it showing the following error $ docker-compose exec -T nginx php bin/console OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"php\": executable file not found in $PATH": unknownMangrove
Now about this error >> you are trying to run PHP command on Nginx container. If you are using the default Nginx image shouldn't have PHP inside that. I belive you are trying to use PHP from symfony_docker_php container.Sequestered
I am following this repo to setup docker for symfony project https://github.com/dunglas/symfony-dockerMangrove
So 1st you need to make "docker compose up", then your both container will start. You can verify that by docker ps command. If both containers are running you can check localhost your application. Also, you can verify PHP from app container like this "docker-compose exec -T app php --version".Sequestered
I already did that and the console returns the following PHP version $ docker-compose exec -T app php --version PHP 7.2.21 (cli) (built: Aug 20 2019 23:29:01) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.21, Copyright (c) 1999-2018, by Zend Technologies with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick RethansMangrove
Let us continue this discussion in chat.Sequestered
Okay, please check the chat consoleMangrove

© 2022 - 2024 — McMap. All rights reserved.