I am working with the Spring framework on a micro services architecture and i am using HTTPS with a self signed certificate (*.mydomainname.fr
).
As registry I am using Eureka and as proxy I am using Zuul. So my services must be registered on Eureka with the name "service-name".mydomainname.fr
because of my certificate. Also, I am not using a DNS for the moment, I am just adding the domain name manually in the /etc/hosts
(127.0.0.1 register.bec3.fr
). Here my micro service architecture.
I would like to dockerise all my services in a docker-compose. My docker-compose.yml is:
version: '3'
services:
registration-service:
image: maven:alpine
container_name: register.bec3.fr
working_dir: /usr/src/spring-boot-app
volumes:
- ./scripts:/usr/src/spring-boot-app/scripts
- ./sslcert:/usr/src/spring-boot-app/ssl
- ./registration-service:/usr/src/spring-boot-app
- ./.m2:/root/.m2
expose:
- 8761
entrypoint: bash -c "keytool -noprompt -import -alias ioteam.bec3 -file /usr/src/spring-boot-app/ssl/ioteam.pem -keystore /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts -storepass xxxxxx && mvn -Dspring.profiles.active=docker spring-boot:run"
#entrypoint: bash -c "/usr/src/spring-boot-app/scripts/addhosts.sh && keytool -noprompt -import -alias ioteam.bec3 -file /usr/src/spring-boot-app/ssl/ioteam.pem -keystore /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts -storepass xxxxxx && mvn -Dspring.profiles.active=docker spring-boot:run"
ports:
- 8761:8761
networks:
back-net:
ipv4_address: 172.20.0.5
aliases:
- register.bec3.fr
depends_on:
- "maria"
proxy-service:
image: maven:alpine
container_name: proxy.bec3.fr
working_dir: /usr/src/spring-boot-app
volumes:
- ./scripts:/usr/src/spring-boot-app/scripts
- ./sslcert:/usr/src/spring-boot-app/ssl
- ./proxy-service:/usr/src/spring-boot-app
- ./.m2:/root/.m2
expose:
- 8888
entrypoint: bash -c "keytool -noprompt -import -alias ioteam.bec3 -file /usr/src/spring-boot-app/ssl/ioteam.pem -keystore /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts -storepass xxxxxx && mvn -Dspring.profiles.active=docker spring-boot:run"
#entrypoint: bash -c "/usr/src/spring-boot-app/scripts/addhosts.sh && keytool -noprompt -import -alias ioteam.bec3 -file /usr/src/spring-boot-app/ssl/ioteam.pem -keystore /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts -storepass xxxxxx && mvn -Dspring.profiles.active=docker spring-boot:run"
ports:
- 8888:8888
networks:
back-net:
ipv4_address: 172.20.0.6
aliases:
- proxy.bec3.fr
depends_on:
- "registration-service"
auth-service:
image: maven:alpine
container_name: auth.bec3.fr
working_dir: /usr/src/spring-boot-app
volumes:
- ./scripts:/usr/src/spring-boot-app/scripts
- ./sslcert:/usr/src/spring-boot-app/ssl
- ./auth-service:/usr/src/spring-boot-app
- ./.m2:/root/.m2
expose:
- 9999
entrypoint: bash -c "keytool -noprompt -import -alias ioteam.bec3 -file /usr/src/spring-boot-app/ssl/ioteam.pem -keystore /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts -storepass xxxxxx && mvn -Dspring.profiles.active=docker spring-boot:run"
#entrypoint: bash -c "/usr/src/spring-boot-app/scripts/addhosts.sh && keytool -noprompt -import -alias ioteam.bec3 -file /usr/src/spring-boot-app/ssl/ioteam.pem -keystore /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts -storepass xxxxxx && mvn -Dspring.profiles.active=docker spring-boot:run"
ports:
- 9999:9999
networks:
back-net:
ipv4_address: 172.20.0.7
aliases:
- auth.bec3.fr
depends_on:
- "maria"
- "registration-service"
maria:
build:
context: ./
dockerfile: maria-dev/Dockerfile
image: maria:latest
container_name: maria
environment:
- MYSQL_ROOT_PASSWORD=xxxxxx
networks:
back-net:
ipv4_address: 172.20.0.3
networks:
back-net:
driver: bridge
ipam:
config:
- subnet: 172.20.0.0/24
So my services can registered to my register service because of that parameter in my application.propertise:
eureka.client.service-url.defaultZone=https://register.bec3.fr:8761/eureka/
My problem is when I am launching those services there names are the docker ID on my eureka dashboard:
and I need something like that :
Because of my certificate. Without that I cannot reach my services with a cURL:
curl -i -XPOST "https://web_app:@register.bec3.fr:8888/auth/oauth/token" -d "grant_type=password&username=toto&password=toto" --cacert my-cert.crt
What can I do ? Can I use a custom hostname in Eureka or should I change my Docker configuration? Thank you, for your help.
I had the same problem. It was for a proof of concept so the way i solved it, was a bit dirty.
Actually you get that 72959axxxxx:auth:9999 in your eureka dashboard and you need auth.mydomainname.fr:auth:9999.
The solution is to add at the top of your /etc/hosts in the docker of your service the domain name of this service. Try to do it with this script:
#!/bin/bash
HOSTS="/etc/hosts"
TMP1="tmp1"
TMP2="tmp2"
IP="192.168.1.1"
DN="domainenameservice"
SERVICE="$IP\t$DN"
echo -e $SERVICE > $TMP1
cat $TMP1 $HOSTS > $TMP2
echo "# test" > $HOSTS
while IFS= read -r var
do
echo "$var" >> $HOSTS
done < $TMP2