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

  • Run nano server container on a Raspberry PI 3
  • Why do I need to give the hostname in netty socketio and how to handle socketio in docker?
  • ASP.NET Core 1.0 EF7 System.Data.SqlClient not found
  • docker cp from host to container is not working
  • Docker Repository Does Not Have a Release File on Running apt-get update on Ubuntu
  • boot2docker malformed HTTP status code “/v1.15/containers/json”
  • 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?

  • How do I pull a local insecure registry image in a rancher service?
  • Running a Docker image in PyCharm causes “Invalid volume specification”
  • Create ssh tunnel to remote docker container running Jupyter Notebook
  • Docker stuck after running background process and detach it
  • Docker swarm - log to rsyslog container
  • Is it possible to customize environment variable by linking two docker containers?
  • 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.