0

I have a spring boot project, and I want to connect it to mysql.

Mysql is in a docker container, I did it with docker-compose.

version : '3'

services:
    mysql:
        image: mysql:8
        container_name: dev_mysql
        environment:
            MYSQL_USER: user
            MYSQL_PASSWORD: user
            MYSQL_ROOT_PASSWORD: root
            MYSQL_DATABASE: MyProject

    phpmyadmin:
        image: phpmyadmin/phpmyadmin:latest
        container_name: dev_pma
        links:
            - mysql
        environment:
            PMA_HOST: mysql
            PMA_PORT: 3306
            PMA_ARBITRARY: 1
        restart: always
        ports:
            - 8090:80
        depends_on:
            - mysql

    couchbase:
        image: couchbase:6.5.1
        container_name: couchbase
        ports:
            - 8091:8091
            - 8092:8092
            - 8093:8093
            - 8094:8094
            - 11210:11210

But i'm not able to reach mysql.

I have tried some url. -localhost:3306/MyProject -{containerIp}:3306/MyProject (i got it from docker inspect dev_mysql) -dev_mysql:3306/MyProject

But none of these worked, i wasn't able to connect.

Any idea ?

Thx for the help (And sry for my bad english xd)

Soratix
  • 1
  • 1
  • 1
    You should expose a port from mysql container in order to connect from the host machine. – leopal May 12 '20 at 13:31
  • I already try to expose a port with `expose : - 3306` but it didn't work too, i updated the docker-compose, to saw you how i did it. – Soratix May 12 '20 at 13:41
  • 1
    It should be 3306:3306 not just 3306. Have you read how port binding works? You can drop that old style “links” everywhere too. This is dinosaur container linking. Not needed anymore. – Mike Doe May 12 '20 at 13:45
  • [expose](https://docs.docker.com/compose/compose-file/#expose) does not publish port on host. Use `port: - 3307:3306` with the appropriate indentation ofc. – leopal May 12 '20 at 13:45
  • 1
    ok, i'm so stupid, i have try to use `ports : - 3306:3306` and it didn't works so i have just ignore this possibility. It works now, thanks ! – Soratix May 12 '20 at 13:50

0 Answers0