Docker Community Forums

Share and learn in the Docker community.

Cannot connect to mysql under container with docker-compose parameters

Hello,

I’m trying to run apache, php and mysql.
And I can’t connect to mysql with MYSQL_USER and MYSQL_PASSWORD parameters i defined on docker-compose file.

This is my docker-compose.yml file :

 version: '3.2'
services:
    apache:
        container_name: apache
        build: .docker/apache/
        restart: always
        volumes:
            - .:/var/www/html/app/
        ports:
            - 80:80
        depends_on:
            - php
            - mysql
        links:
            - mysql:mysql
    php:
        container_name: php
        build: .docker/php/
        restart: always
        volumes:
            - .:/var/www/html/app/
        working_dir: /var/www/html/app/

    mysql:
        container_name: mysql
        image: mysql
        restart: always
        volumes:
            - .docker/data/db:/var/lib/mysql
        environment:
            MYSQL_DATABASE: app
            MYSQL_ROOT_PASSWORD: test
            MYSQL_USER: test
            MYSQL_PASSWORD: test

When i try to run the command under mysql container : mysql -utest -ptest
I have access denied, but i’m only able to connect with mysql -uroot -proot

Help me please.
Thanks.

Did you change the password in the compose file after you have initialized the volume? MYSQL_USER and MYSQL_PASSWORD are used with CREATE USER, they don’t update an existing one.