Unable to connect to mysql in docker container from another docker container

36
April 15, 2019, at 12:40 PM

I have two docker containers: mysql and spring boot service.
Service container is not connecting to mysql container(failing on the deploy) with following exception: CommunicationsException: Communications link failure
So far I have tried using docker --link, docker networks, running everything using/without docker compose. I am able to connect to DB container outside of docker.

Connection string: jdbc:mysql://db:3306/somedb

docker-compose.yml

version: '3.7'
services:
  app:
    build: .
    restart: unless-stopped
    ports:
    - "80:8060"
    links:
    - db
    depends_on:
    - db
  db:
    image: "mysql:latest"
    command: --default-authentication-plugin=mysql_native_password
    environment:
    - MYSQL_DATABASE=somedb
    - MYSQL_ROOT_PASSWORD=somepassword
    ports:
    - "3306:3306"
    volumes:
    - /Users/someuser/someproject/mysql/data:/var/lib/mysql
Answer 1

I had the same problem earlier and i tried with by changing the mysql image version. Here is my compose yaml file where i am able to connect it with.

version: "3.0"
services:
  spring-boot-container:
    build: .
    ports:
      - "8086:8086"
    links: 
      - mysql-standalone
  mysql-standalone:
    image: mysql:5.6
    ports:
      - "3307:3306"
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: springsecurity
      MYSQL_USER: sa
      MYSQL_PASSWORD: password
READ ALSO
How to Group result from MSQL db by month from a milliseconds column?

How to Group result from MSQL db by month from a milliseconds column?

I'm trying to get total number of item based on month from MSQL database using SLIM framework, When i display data i get result but separated even if there are in the same monthMy code are,

27
i am getting error while using NEW.id in database triggers

i am getting error while using NEW.id in database triggers

i am trying to create a trigger for inserting dataand I want to get the current id for that author or user who is inserting or change in table

29
Creating Unique Index And Insert Data

Creating Unique Index And Insert Data

I am making different question regarding on my problemThey suggest me on this thread Best way to avoid duplicate entry into mysql database Thank you for pointing out this thread on me

23
How can I set up password-less in ssh2_connect login?

How can I set up password-less in ssh2_connect login?

I have gone through the post where I can do ssh without giving password [https://askubuntucom/a/296574/905016] But I want to login through ssh2_connect in php, where I need to give password detail

45