1

I've got a Symfony2 application in a docker project, using docker-compose.

I get the following error when trying to run schema updates to my database. [Doctrine\DBAL\Exception\DriverException] An exception occured in driver: SQLSTATE[HY000] [1130] Host '172.17.0.129' is not allowed to connect to this MySQL server

My docker-compose.yml file:

api:
  build: images/nginx
  ports:
    - "80:80"
    - "9000:9000"
  links:
    - mysql:mysql
    - memcached:memcached
    - redis:redis
    - elasticsearch:elasticsearch
    - rabbitmq:rabbitmq
  volumes:
    - www/api:/var/www
    - sites/api:/etc/nginx/sites-enabled

socketserver:
  build: images/socketserver
  links:
    - rabbitmq:rabbitmq
  ports:
    - "5000:5000"
  volumes:
    - www/socketserver:/var/www
    - sites/socketserver:/etc/nginx/sites-enabled

adminpanel:
  build: images/adminpanel
  ports: 
    - "8001:8001"
  volumes:
    - www/adminpanel:/var/www
    - sites/adminpanel:/etc/nginx/sites-enabled

mysql:
  image: mysql:latest
  expose:
    - "3306"
  ports:
   - "3307:3306"
  environment:
    MYSQL_DATABASE: api
    MYSQL_USER: root
    MYSQL_PASSWORD: [REDACTED]
    MYSQL_ROOT_PASSWORD: [REDACTED]

memcached:
  image: tutum/memcached
  ports:
    - "11211:11211"
  dns: 3.3.3.3
  environment:
    MEMCACHED_PASS: [REDACTED]

redis:
  image: tutum/redis
  ports:
    - "6379:6379"
  dns: 4.4.4.4
  environment:
    REDIS_PASS: [REDACTED]

elasticsearch:
  image: tutum/elasticsearch
  ports:
    - "9200:9200"
  dns: 5.5.5.5
  environment:
    ELASTICSEARCH_USER:[REDACTED]
    ELASTICSEARCH_PASS:[REDACTED]

rabbitmq:
  image: dockerfile/rabbitmq
  dns: 6.6.6.6
  ports: 
    - "5672:5672"
    - "15672:15672"

My Symfony2 parameters.yml:

  parameters:
      secret:           [REDACTED]
      locale:            en
      mailer_transport:  smtp
      mailer_host:       [REDACTED]
      mailer_user:      test@theladbible.com
      mailer_password:  [REDACTED]
      database_driver:   pdo_mysql
      database_host:     mysql
      database_port:     3306
      database_name:     api
      database_user:     root
      database_password: [REDACTED]
      jms_serializer.cache_naming_strategy.class: JMS\Serializer\Naming\IdenticalPropertyNamingStrategy

I've tried multiple different ways. I can't connect via localhost or 127.0.0.1. Putting 'mysql' seemed to link to the database containers correct database address, but then I still get that error shown above.

I'm new to Docker, so I've probably misunderstood some of the fundamentals, apologies if that's the case.

I suspect I need to add the correct user permissions in perhaps? I haven't been able to connect to the database container directly to do this either.

Thanks in advance!

Ewan Valentine
  • 3,741
  • 7
  • 43
  • 68
  • Is the mysql user `root@'localhost'` or `root@'%'`? The connection to your mysql DB from `@'localhost'` won't work as your request isn't local. http://stackoverflow.com/questions/19101243/error-1130-hy000-host-is-not-allowed-to-connect-to-this-mysql-server – Céline Aussourd Mar 25 '15 at 16:59
  • Also you should check the **Caveats** section in https://registry.hub.docker.com/_/mysql/ – Céline Aussourd Mar 25 '15 at 17:08
  • @CélineAussourd As you can see from y parameters.yml file, the host is set to ```database_host: mysql``` which is pointing to whatever IP address the mysql container assigns. I'm not pointing at localhost or 172.0.0.1 for the reasons you just pointed out. Looking at the caveats now, I'm not entirely sure that's what my issue is. I guess it could be, though I'm not sure how I'd resolve that. – Ewan Valentine Mar 25 '15 at 17:36
  • I'm not entirely sure why someone's down-voted me on this one... – Ewan Valentine Mar 25 '15 at 17:36
  • I mean your MySQL database might not be configured to allow incoming connections from remote users. Your parameters.yml is fine. Did you try setting up access to your DB with another `MYSQL_USER` than `root`? (it will imply also a change in your parameters.yml) – Céline Aussourd Mar 25 '15 at 17:44
  • Looking at the Mysql docker image code https://github.com/docker-library/mysql/blob/master/5.6/docker-entrypoint.sh and it seems they are granting access to `root@'%'` so it should work... sorry, it looks like it's not what I thought it was. – Céline Aussourd Mar 25 '15 at 17:48
  • btw, why do you have `"3307:3306"` in your mysql configuration and not `"3306:3306"`? – Céline Aussourd Mar 25 '15 at 17:52

1 Answers1

4

Solved this issue by using https://registry.hub.docker.com/u/drakedroid/mysql-with-data/ which extends the default mysql docker image, but automatically configures everything so you can access it from other containers.

In your parameters.yml, set your host as the same name of your mysql docker name.

So in my case, my mysql docker-compose config:

mysql:
  image: drakedroid/mysql-with-data
  expose:
    - "3306"
  ports:
   - "3306:3306"
  environment:
    MYSQL_DATABASE: api_master
    MYSQL_USER: root
    MYSQL_PASSWORD: [REDACTED]
    MYSQL_ROOT_PASSWORD: [REDACTED]

In my parameters.yml

database_host:     mysql

That way Docker automatically figures it all out for you.

Ewan Valentine
  • 3,741
  • 7
  • 43
  • 68