Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add phpmyadmin to laravel 8 sail docker-compose.yml

I'm trying to add phpmyadmin to laravel 8 docker-compose.yml file.

Now, I can access phpmyadmin on "http://localhost:8080" but the user is not got Cannot log:

Cannot log in to the MySQL server

mysqli::real_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known

mysqli::real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known

enter image description here

My docker-compose.yml file looks like this:

# For more information: https://laravel.com/docs/sail
version: "3"
services:
  laravel.test:
    build:
      context: ./vendor/laravel/sail/runtimes/8.0
      dockerfile: Dockerfile
      args:
        WWWGROUP: "${WWWGROUP}"
    image: sail-8.0/app
    ports:
      - "${APP_PORT:-80}:80"
    environment:
      WWWUSER: "${WWWUSER}"
      LARAVEL_SAIL: 1
    volumes:
      - ".:/var/www/html"
    networks:
      - sail
    depends_on:
      - mysql
      # - pgsql
      - redis
      # - selenium
  # selenium:
  #     image: 'selenium/standalone-chrome'
  #     volumes:
  #         - '/dev/shm:/dev/shm'
  #     networks:
  #         - sail
  mysql:
    image: "mysql:8.0"
    ports:
      - "${FORWARD_DB_PORT:-3306}:3306"
    environment:
      MYSQL_ROOT_PASSWORD: "${DB_PASSWORD}"
      MYSQL_DATABASE: "${DB_DATABASE}"
      MYSQL_USER: "${DB_USERNAME}"
      MYSQL_PASSWORD: "${DB_PASSWORD}"
      MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
    volumes:
      - "sailmysql:/var/lib/mysql"
    networks:
      - sail
    healthcheck:
      test: ["CMD", "mysqladmin", "ping"]
  #    pgsql:
  #        image: postgres:13
  #        ports:
  #            - '${FORWARD_DB_PORT:-5432}:5432'
  #        environment:
  #            PGPASSWORD: '${DB_PASSWORD:-secret}'
  #            POSTGRES_DB: '${DB_DATABASE}'
  #            POSTGRES_USER: '${DB_USERNAME}'
  #            POSTGRES_PASSWORD: '${DB_PASSWORD:-secret}'
  #        volumes:
  #            - 'sailpostgresql:/var/lib/postgresql/data'
  #        networks:
  #            - sail
  redis:
    image: "redis:alpine"
    ports:
      - "${FORWARD_REDIS_PORT:-6379}:6379"
    volumes:
      - "sailredis:/data"
    networks:
      - sail
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
  # memcached:
  #     image: 'memcached:alpine'
  #     ports:
  #         - '11211:11211'
  #     networks:
  #         - sail
  mailhog:
    image: "mailhog/mailhog:latest"
    ports:
      - "${FORWARD_MAILHOG_PORT:-1025}:1025"
      - "${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025"
    networks:
      - sail

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    links:
      - mysql:mysql
    ports:
      - 8080:80
    environment:
      MYSQL_USERNAME: "${DB_USERNAME}"
      MYSQL_ROOT_PASSWORD: "${DB_PASSWORD}"
      PMA_HOST: mysql

networks:
  sail:
    driver: bridge
volumes:
  sailmysql:
    driver: local
  #    sailpostgresql:
  #        driver: local
  sailredis:
    driver: local

like image 591
Mansour Alnasser Avatar asked Feb 14 '21 11:02

Mansour Alnasser


People also ask

Can you use phpMyAdmin with laravel?

Put phpmyadmin directory in /public folder of laravel project directory. It will work comfortably, and not mess up with laravel config.

Do you need Docker for laravel sail?

Introduction. Laravel Sail is a light-weight command-line interface for interacting with Laravel's default Docker development environment. Sail provides a great starting point for building a Laravel application using PHP, MySQL, and Redis without requiring prior Docker experience.


1 Answers

For containers to communicate with each other, they have to be on the same Docker network. You've explicitly assigned the mysql container to networks: [sail], but the phpmyadmin container isn't on that network. You can add

services:
  phpmyadmin:
    networks:
      - sail

Compose also provides a network named default for you (see Networking in Compose for more details). If you don't explicitly specify networks: for a service then it will be on the default network. Another solution could be to just delete all of the networks: blocks everywhere in the file to let every container be on the default network.

links: only are used with an obsolete form of Docker networking, and you can delete that part of the file as well.

like image 187
David Maze Avatar answered Oct 10 '22 09:10

David Maze