Home>

Hello everyone! I can not connect to the database, which is based on the mysql image. Writes The driver has not received any packets from the server. Connection refused.

Dockerfile:

FROM openjdk:17 as build
WORKDIR /app
COPY build/libs/userlist-0.0.1-SNAPSHOT.jar userlist-0.0.1-SNAPSHOT.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","userlist-0.0.1-SNAPSHOT.jar"]

Docker compose:

version: "3.7"
  services:
    api_service:
      build: .
      ports:
        -8080:8080
      environment:
        SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/user_list?autoReconnect=true&
useSSL=false
      depends_on:
        -db
    db:
      image:mysql:8.0
      ports:
        -3307:3306
      restart: always
      volumes:
        -./data:/var/lib/mysql
      environment:
        MYSQL_ROOT_PASSWORD: annaanna18
        MYSQL_DATABASE: user_list
        MYSQL_USER: root
        MYSQL_PASSWORD: annaanna18
    client:
      container_name: user-client
      image:front
      ports:
        -3000:3000

Application.properties:

database.url=jdbc:mysql://db:3306/user_list?autoReconnect=true&
useSSL=false
database.username=root
database.password=annaanna18

Text information (code and configs) should be given in the question as text, not screenshots.

insolor2022-01-26 06:54:13

Thanks I'll know

Анна2022-01-26 06:54:13

3307:3306 -expose port 3307 outside, and try to access 3306.

aleksandr barakin2022-01-26 06:54:13

Alexander, Anna refers to the mysql server by the name of the service, and inside the container, port 3306 is listening.

Aleksey Vaganov2022-01-26 06:54:13