Skip to content

Latest commit

 

History

History
57 lines (54 loc) · 1.84 KB

README.md

File metadata and controls

57 lines (54 loc) · 1.84 KB

TO CREATE SQL TABLE

CREATE TABLE Users(id int NOT NULL AUTO_INCREMENT PRIMARY KEY, name varchar(255));
INSERT INTO Users(name) VALUES ('Oscar');

TO ENTER SQL

mysql -p

NORMAL COMMAND

docker run -p 3307:3306 --name mysqldb -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=Test mysql

If i want my docker to communicate with another container, i have to create a bridge network

docker run -d -p 3307:3306 --name mysqldb2 --network privet-net -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=Test mysql
docker network create --driver bridge privet-net

Same with the spring server

docker run -d -p 8080:8080 --network privet-net --name mysql-spring-server spring-mysql-server-app

To access the other container, jdbc change from to

spring.datasource.url=jdbc:mysql://localhost:3307/Test?useSSL=false&useUnicode=true&useLegacyDatetimeCode=false?allowPublicKeyRetrieval=true
spring.datasource.url=jdbc:mysql://mysqldb2:3306/Test?useSSL=false&useUnicode=true&useLegacyDatetimeCode=false?allowPublicKeyRetrieval=true

Where mysqldb2 is the docker container of the mysql

To create the spring server

mvn clean package

In Dockerfile

FROM openjdk:18
WORKDIR /app
COPY ./target/TestAppV2-0.0.1-SNAPSHOT.jar /app
EXPOSE 8080
CMD ["java", "-jar", "TestAppV2-0.0.1-SNAPSHOT.jar"]

Then just build the image as we have done in the other docker project.

Now i have a docker compose that does all automatically.

docker-compose up

Change the flag allowKeyRetrieval from false to true

allowKeyRetrieval=TRUE

att: we have to create the Users db (as i said)

CREATE TABLE Users(id int NOT NULL AUTO_INCREMENT PRIMARY KEY, name varchar(255));

* WE CAN USE SPRING JPA TO CREATE THE USERS TABLE AUTOMATICALLY AND USE JPAREPOSITORY COMMANDS