Symfony – Unknown MySQL server host when using command line

So for some reason when I run for example cache:clear I get the following error:

mysql error

  • Docker output of exec command in detach mode
  • How to go from Apache Kafka to Confluent Platform?
  • Create a volume in docker from windows host
  • create a web2py docker image and access it through browser
  • [pacemaker]Docker compose autostart
  • Docker - port prevents listening
  • But when I view the application through the browser it seem to connect fine to the database because when I edit the parameters.yml with incorrect data it throws an error in the browser saying it cannot connect.

    I’m using docker and i have the following settings:

      image: zimmobe/php:5.6-apache-oraclelinux
        - ./:/var/www/project/
        - SYMFONY_ENV=dev
        - SYMFONY_DEBUG=1
        - BASE_DIR=/var/www/project
        - mysql
        - 3005:80
       image: mysql:5.6
         MYSQL_ROOT_PASSWORD: root
         MYSQL_DATABASE: minecraftweb
         - 3306:3306

    and my parameters.yml looks like this:

        database_host: mysql
        database_port: 3306
        database_name: minecraftweb
        database_user: root
        database_password: root
        mailer_transport: smtp
        mailer_user: null
        mailer_password: null
        secret: ThisTokenIsNotSoSecretChangeIt

    So any reason why the command line throws an error but not the application in the browser?

  • Docker workflow
  • Docker Container fails to connect to remote SQL
  • Writable folder permissions in docker
  • Multiple dockerfiles in one docker or multiple images from one dockerfile
  • Integration Tests with Microservices (NodeJS), Jenkins and Docker
  • Jenkins - Cannot run program “docker”
  • One Solution collect form web for “Symfony – Unknown MySQL server host when using command line”

    You should launch the command inside the container, an example ( of a probably script):

    docker-compose \
        -f docker-compose.yml \
        run --rm --entrypoint bash php -c \
        "id -u dockeruser &> /dev/null || useradd -r -g users -u $USER_ID --base-dir /tmp dockeruser && su dockeruser -c 'bin/console cache:clear'"

    Hope this help

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.