Docker Community Forums

Share and learn in the Docker community.

Connect docker + Laravel to my localhost database or server database

Hi,

 I'm new in docker, so need some help regarding making connection to localhost database or server database to my docker application. So I don't want to use docker image like mysql or mariadb to connect my application, but want to use localhost database to make connection to docker application. Can you please help me how I can achieve that?

Below is my yml file, so I need to know should I've to use mariadb image in order to use external database, because I don't want to use docker mariadb image for connection.


  version: '3.7'

  services:
    web:
      container_name: ${APP_NAME}

      build:
        context: .
        dockerfile: ./Dockerfile

      ports:
        - "8081:80"

      volumes:
        - ./:/var/www/html/laravel

      depends_on:
        - mariadb

      links:
        - mariadb

    mariadb:
      image: mariadb
      container_name: mariadb
      command: --default-authentication-plugin=mysql_native_password
      environment:
        MYSQL_ROOT_PASSWORD: password
        MYSQL_DATABASE: laravel
        MYSQL_USER: root
        MYSQL_PASSWORD: passowrd
      ports:
        - "3309:33091"

Your application just needs to know the database server’s IP or hostname (config/database.php), it can be an environment variable or explicitly defined.

Thanks, I already have that figured out. I appreciate your response.