0

I am trying to put an application on docker spring-boot + mysql. The problem is that I am working on a MacBook M1 and all my attempts fail.

I get the database image from dockerhub, the application image also builds for me without any hindrance but the application won't start because there is a database connection error.

My Dockerfile

FROM arm64v8/openjdk:11.0.15-jdk-bullseye
ADD target/patient-registration-0.0.1-SNAPSHOT.jar .
EXPOSE 8080
CMD java -jar patient-registration-0.0.1-SNAPSHOT.jar

My docker-compose.yml

version: '3.8'
services:
 database:
  container_name: patient_db
  image: 'mysql:8.0.22'
  platform: linux/x86_64
  environment:
    - MYSQL_ROOT_PASSWORD=mysql
    - MYSQL_USER=mysql
    - MYSQL=patient_db
    - MYSQL_PORT=3306
  restart: always
 patient_reservation:
  image: 'patient_reservation'
  build: .
  ports:
   - "8282:8282"
 environment:
   - SPRING_DATASOURCE_URL=jdbc:mysql://database:3306/patient_db?useUnicode=true&characterEncoding=utf8&useSSLdo=false&useLegacyDatetimeCode=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
   - SPRING_DATASOURCE_USERNAME=mysql
   - SPRING_DATASOURCE_PASSWORD=mysql
   - SPRING_JPA_HIBERNATE_DDL_AUTO=update
 restart: always
 depends_on:
   - database

I would greatly appreciate it!

Thank you in advance !

  • Is the file exactly like that? Because I see indentation issues… – Sami Kuhmonen May 11 '22 at 20:07
  • I got the indentation split here on stackoverflow - in my project Dockerfile and Docker-compose have the correct indentation – grzesiek136 May 11 '22 at 20:32
  • Welcome, grzesiek136! Take a look at https://stackoverflow.com/questions/49019652/not-able-to-connect-to-mysql-docker-from-local/67952281#67952281 which has some suggestions. Also, looks like you are not setting the password for database user mysql in the database environment ... MYSQL_PASSWORD. – Beel May 11 '22 at 21:49
  • Oh, and the dockerfile exposes 8080, but you're mapping 8282 in docker-compose. – Beel May 11 '22 at 21:50
  • Annnddd ... one more note ... you're running on an m1? And you're building an arm app via the dockerfile. BUT ... you're specifying an intel image for mysql. Is that intended? – Beel May 11 '22 at 21:55
  • 1
    @grzesiek136 could you fix the identation issues so it looks exactly like your own file? – tbjorch May 12 '22 at 06:39

0 Answers0