skip to Main Content

i have a little problem with mysql server.
i created my docker-compose.yml, but when i want to access to phpMyAdmin (localhost:8080), an error message appeared sais that:
“phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. Please check the values โ€‹โ€‹of host, username and password in the configuration and make sure they match the information provided by the MySQL server administrator”.

Here is my docker-compose file and thanks for helping me

version: '2'
services:
  apache:
    image: rafaelcgstz/magento2
    # build: .
    ports:
      - 80:80
      - 9001:9000
      # - "35729:35729" # live reload
    volumes:
      - ./src:/var/www/html
      - ~/.composer:/var/www/.composer
      - ~/.npm:/var/www/.npm
      # - ~/.nvm:/var/www/.nvm
    environment:
      XDEBUG_CONFIG: "remote_host=localhost"
      PHP_IDE_CONFIG: "serverName=Docker"
    depends_on:
      - db
    links:
      - db
    networks:
      - magento-network

  db:
    image: mariadb
    ports:
     - 3300:3306
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=magento
      - MYSQL_USER=magento
      - MYSQL_PASSWORD=magento
    volumes:
      - dbdata:/var/lib/mysql
    networks:
      - magento-network

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    environment:
     - PMA_HOST=db
     - PMA_USER=root
     - PMA_PASSWORD=root
     - MYSQL_ROOT_PASSWORD=root
    ports:
     - 8080:80
    networks:
      - magento-network

  redis:
    image: redis
    ports:
     - 6379
    networks:
      - magento-network

  redis-session:
    image: redis
    ports:
     - 6379
    networks:
      - magento-network

  mailhog:
    image: mailhog/mailhog
    ports:
      - 1025:1025
      - 8025:8025
    networks:
      - magento-network

networks:
  magento-network:
    driver: bridge

volumes:
  dbdata:
    driver: local

3

Answers


  1. Seems like you have a typo in mariadb service definition:

    ports:
         - 3300:3306
    

    You configured port mapping so that container is reachable at 3300 but you did not pass this information to PHPMyadmin. As a result connection attempt just times out.

    Side note: you do not need to expose port for database at all – other containers will communicate with it using Docker’s virtual network and for local access you can use docker container -it exec <container-id> mysql... or docker-compose exec db mysql...

    Login or Signup to reply.
  2. while it appears there is a typo for the port with this post I want to point out that it’s important to make sure that your user has access ‘TO’ and ‘FROM’ the appropriate IP.

    This is an (wide open -adjust as needed) example for updating the access domain when running adminer / phpadmin via docker:

    GRANT ALL ON . TO ‘admin’@’172.18.0.0/255.255.255.0’ IDENTIFIED BY ‘password’ WITH GRANT OPTION;

    p.s. I’m adding this answer here because I also landed on this page with the same error.

    Login or Signup to reply.
  3. I solved my problem with this command:

    docker-compose destroy
    sudo rm -rf db/
    docker-compose up -d
    docker-compose web
    composer install
    symfony d:m:m --no-interaction
    symfony d:f:l --no-interaction
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search