How to setup Docker Network between Microservices
1. Eureka server
2. Order service
3. Product service
4. MySQL docker container
Steps to run mysql docker container
sudo docker pull mysql/mysql-server:5.5
sudo docker run --name=mysql1 -e MYSQL_ROOT_HOST=% -p 3306:3306 -d
mysql/mysql-server:5.5
sudo docker logs mysql1 2>&1 | grep GENERATED
--this give generated root password
sudo docker exec -it mysql1 mysql -u root -p
password: give the generated password
this will take to sql shell
CREATE USER 'newUser'@'%' IDENTIFIED BY '<<generated password>>';
GRANT ALL PRIVILEGES ON *.* TO 'newUser'@'%' WITH GRANT OPTION;
Dockerfile
FROM openjdk:17-jdk-alpine
ARG JAR_FILE
COPY ${JAR_FILE} springbootapp.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-
jar","springbootapp.jar"]
sudo docker run -p 1111:1111 regservice
User network host so that these containers will use ip address or host name
sudo docker run --network host -p 9090:9090 productservice
sudo docker run --network host -p 8090:8090 orderservice
Attached is Eureka server dashboard which will display ip address of containers
When we try to access ordesrevice, this will get dynamically ip address of product
service from Eureka server and hit the product service url