0

My Docker (v.2) docker-compose.yml file has 2 Ubuntu images and 2 MariaDB images:

app:
    container_name: app
    image:php-apache-dev:ubuntu-16.04
    links:
      - mysql
    depends_on:
      - mysql
    ports:
      - '8443:443'
    volumes:
      - .:/app
    environment:
      docker: 'true'
      PHP_DEBUGGER: 'xdebug'
      WEB_DOCUMENT_ROOT: '/app/public'
      WEB_NO_CACHE_PATTERN: '\.(.*)$$'
      working_dir: '/app'
      CONF_FILE: 'conf/local/develop.php'
  test:
      container_name: test
      image:php-apache-dev:ubuntu-16.04
      links:
        - mysql_test
      depends_on:
        - mysql_test
      ports:
        - '8444:443'
      volumes:
        - .:/app
      environment:
        docker: 'true'
        WEB_DOCUMENT_ROOT: '/app/public'
        WEB_NO_CACHE_PATTERN: '\.(.*)$$'
        working_dir: '/app'
        CONF_FILE: 'conf/local/test.php'
  mysql:
    image: mariadb:latest
    ports:
      - '3306:3306'
    environment:
      MYSQL_ROOT_PASSWORD: 'dev'
      MYSQL_DATABASE: 'dev'
      MYSQL_USER: 'dev'
      MYSQL_PASSWORD: 'dev'
  mysql_test:
    image: mariadb:latest
    ports:
      - '3307:3306'
    environment:
      MYSQL_ROOT_PASSWORD: 'dev'
      MYSQL_DATABASE: 'dev_test'
      MYSQL_USER: 'dev'
      MYSQL_PASSWORD: 'dev'

One is for development, one is for testing. When I access the first one (on localhost:4443) it works. When I access the second one (on localhost:4444) I am able to view the website, but it denies access to the user:

Access denied for user 'dev'@'%' to database 'dev_test'

My configuration for the second site is set up to access the second MySQL port/user:

'db_port'             => env('DB_PORT', '3307'),
'db_name'             => env('DB_NAME', 'dev_test'),

I tried the answer to this question but without success. If I docker exec bash into the test database image, and run SHOW GRANTS FOR dev, it says:

GRANT ALL PRIVILEGES ON `dev_test`.* TO 'dev'@'%'
GluePear
  • 7,244
  • 20
  • 67
  • 120
  • Possible duplicate of [connecting to a docker-compose mysql container denies access but docker running same image does not](https://stackoverflow.com/questions/37459031/connecting-to-a-docker-compose-mysql-container-denies-access-but-docker-running) – William Perron May 04 '18 at 14:57
  • What MySQL `host` are you using in your second site? – nikoskip May 04 '18 at 15:18
  • @nikoskip I could kiss you. I forgot to update it. Make that an answer & I'll mark it right. – GluePear May 04 '18 at 15:30

1 Answers1

1

You probably forgot to use the correct MySQL host in your second site.

nikoskip
  • 1,860
  • 1
  • 21
  • 38