Home  >  Q&A  >  body text

Docker Compose - Connection to Phpmyadmin and MySQL not working

<p>I need an easy way to create an environment with PHP, NGINX, MySQL, and phpmyadmin using Docker-compose. </p> <p>I have successfully created a PHP environment using NGINX. </p> <p>Now I want to add a database with MySQL and phpmyadmin. These two components don't seem to work. For example, I cannot access phpmyadmin by specifying port "8081". I access the local server using the local IP address and the port at the end of the address. </p> <p>When I want to call phpmyadmin, the browser window tells me "Unable to connect to server". </p> <p>This is the docker-compose.yml file: </p> <pre class="brush:yaml;toolbar:false;">version: "3.9" services: web: image: nginx:latest ports: - "8080:80" volumes: - ./src:/var/www/html - ./default.conf:/etc/nginx/conf.d/default.conf links: -php-fpm php-fpm: image: php:8-fpm volumes: - ./src:/var/www/html mysql: image:mysql container_name: mysql environment: MYSQL_ROOT_PASSWORD: '<mypassword>' MYSQL_DATABASE:baton MYSQL_USER:baton MYSQL_PASSWORD: '<mypassword>' ports: - "3306:3306" volumes: - ./database/mysql:/var/lib/mysql phpmyadmin: image: phpmyadmin/phpmyadmin container_name: pma links: - mysql environment: PMA_HOST: mysql PMA_PORT: 3306 PMA_ARBITRARY: 1 restart: always ports: - 8081:80 </pre> <p>Hope everyone can help! </p>
P粉615886660P粉615886660418 days ago592

reply all(1)I'll reply

  • P粉564301782

    P粉5643017822023-08-29 00:26:38

    Now I found that I made a mistake when connecting to the database through phpmyadmin. I got the second database and it's already running on port 3306. I have now switched to the existing database and the connection now works!

    reply
    0
  • Cancelreply