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:      [email protected]
      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!

7
  • Is the mysql user root@'localhost' or root@'%'? The connection to your mysql DB from <a_user>@'localhost' won't work as your request isn't local. stackoverflow.com/questions/19101243/… Commented Mar 25, 2015 at 16:59
  • Also you should check the Caveats section in registry.hub.docker.com/_/mysql Commented Mar 25, 2015 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. Commented Mar 25, 2015 at 17:36
  • I'm not entirely sure why someone's down-voted me on this one... Commented Mar 25, 2015 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) Commented Mar 25, 2015 at 17:44

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

do you mean your parameters.yml now contains only this parameter and nothing else ?
No this was just an excerpt of my database container config @allan.simon
This seems to work also with the official mysql repo. I can see the hosts defined in /etc/hosts for each linked containers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.