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

  • What does it mean that `docker run --network=container:CONTAINERID`?
  • How to restore snapshot of docker image (for testing purpose, every test on this same docker image)
  • Meaning of “$PWD”:/path/to/directory"
  • Docker-client Java: How to keep instances running?
  • Docker image build as AWS CodePipeline step
  • How can you run multiple docker containers from your computer, and have each use a different IP (using a VPN)?
  • 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?

  • Why use AUFS as the default Docker storage backend instead of devicemapper?
  • Flow of registration between kafka and zookeeper
  • Unable to activate chef-provisioning-docker-0.6 because chef-provisioning-1.1.1 conflicts with chef-provisioning (~> 0.9)
  • docker -v and symlinks
  • docker interactive mode exits after ENTRYPOINT
  • Docker API - how do I join a network?
  • 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.