#[Docker] SQLSTATE[HY000] [2002] Connection refused

19 messages · Page 1 of 1 (latest)

sweet cloud
#

I cant get a connection to my mariadb container. tried localhost, 127.0.0.1, container ip, container name)

.env

DB_CONNECTION=mysql
DB_HOST=mariadb
DB_PORT=3307
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=laravel

docker-compose

version: "3"
services:
  web:
    image: 'nginx:alpine'
    volumes:
      - './www:/srv/backend:rw'
      - './docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf'
    # ports:
    #   - 80:80
    networks:
      - default
      - traefik_proxy
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik_proxy"
      - "traefik.http.routers.hotelbooking.rule=HostRegexp(`hotelbooking.test`)"
      - "traefik.http.routers.hotelbooking.service=hotelbooking"
      - "traefik.http.routers.hotelbooking.priority=1"
      - "traefik.http.services.hotelbooking.loadbalancer.server.port=80"
    restart: always

  php:
    build: ./docker/backend
    volumes:
      - ./www:/srv/backend
    networks:
      - default
    restart: always

  mariadb:
    image: 'mariadb:10.6'
    volumes:
      - ./mariadb:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=dev
      - MYSQL_DATABASE=laravel
      - MYSQL_USER=laravel
      - MYSQL_PASSWORD=laravel
    ports:
      - '3307:3306'
    networks:
      - default
    restart: always

  redis:
    image: 'redis:latest'
    ports:
      - '6379:6379'
    networks:
      - default
    restart: always

  mailhog:
    image: mailhog/mailhog
    ports:
      - "8025:8025"
      - "1025:1025"
    networks:
      - default
    restart: always

networks:
  default:
    driver: bridge
  traefik_proxy:
    external: true
grand badge
#

Try removing the environment variables MYSQL_USER and MYSQL_PASSWORD

#

And make connection with these settings:

Host: localhost
Username: root
Password: dev
Database: laravel
Port: 3306
sweet cloud
#

SQLSTATE[HY000] [2002] No such file or directory

grand badge
#

Can you try connecting with it through a dbms first?

#

see if it's even reachable

sweet cloud
#

i can connect to it using dbeaver on host machine with no problems

grand badge
#

Gotcha

sweet cloud
grand badge
#

Current .env values for your database connection?

sweet cloud
#
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3307
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=dev
#

also tried 3306

grand badge
#

DB_HOST needs to be mariadb

#

100% sure about that one

#

Pretty sure port should be 3306

sweet cloud
#

Holy crap, why did it only work with 3306 and host mariadb ?

sweet cloud
#

Thx bud 🙂