Docker Compose - Service name not working as environment variable - docker-compose

I'm trying to use docker-compose to setup a Spring Cloud project.
I'm using spring cloud configuration so I have a Configuration Server and some services.
For now, I have 3 services in my docker-compose.yml
version: '3'
services:
db:
image: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: 'root' # TODO: Change this
MYSQL_USER: 'user'
MYSQL_PASS: 'password'
MYSQL_ROOT_HOST: '%'
volumes:
- "db:/opt/mysql/docker:rw"
ports:
- "3307:3306"
config:
image: config-server
restart: always
depends_on:
- db
environment:
- SPRING_DATASOURCE_URL=jdbc:mysql://db:3306/ec_settings?createDatabaseIfNotExist=true&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
ports:
- "8100:8100"
gateway:
image: gateway
restart: always
depends_on:
- config
environment:
- CONFIG_URI=http://config:8100
ports:
- '8081:8080'
volumes:
db: {}
In gateway microservice, in bootstrap.yml, i have this setting
spring:
cloud:
config:
uri: ${CONFIG_URI}
When i put up the docker composer i see that gateway service is trying to fetch configuration from http://config:8100
Fetching config from server at : http://config:8100
So, the variable passes to Spring Boot but docker-compose does not replace the service name with its actual link.
The very strange thing is that SPRING_DATASOURCE_URL environment variable gets translated correctly in config service to connect to db service.

I finally solved it thanks to this link Docker - SpringConfig - Connection refused to ConfigServer
The problem was the service was trying to fetch the config url too early.
Solution is to put in bootstrap.yml this settings
spring:
cloud:
config:
fail-fast: true
retry:
max-attempts: 20

Related

How to set jdbc url to connect to database container

I'm usiing docker-compose to containerize my rest api. One service for my spring app et the other for the database. The probleme is the spring boot api try to connect by default to the database by using localhost but since it is the container it create an error ( Connection to localhost:5432 refused. Check that the hostname and port). And the container stop working since the app don't work. How to tell to my spring boot api to try to conect to the database container.
version: "3"
services:
app_service:
container_name: app_service
build: .
ports:
- "8080:8080"
depends_on:
- postgresql
networks:
- net
postgresql:
image: postgres:15.0
container_name: db
ports:
- "5432:5432"
restart: unless-stopped
environment:
POSTGRES_PASSWORD : Access/fedora/6
POSTGRES_DB : postgres
volumes:
- psql:/var/lib/postgres/psql
networks:
- net
volumes:
psql:
networks:
net:
cloud:
aws:
credentials:
secret-key: 'qdfqdfqsdfqsdqsdfqsdfqs'
access-key: 'qfqsdfqserfqegdrhfjkgkh'
region:
static: eu-west-3
stack:
auto: 'false'
spring:
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
format_sql: 'true'
show-sql: 'true'
hibernate:
ddl-auto: update
servlet:
multipart:
max-file-size: 5MB
enabled: 'true'
max-request-size: 10MB
file-size-threshold: 2MB
datasource:
hikari:
jdbc-url: jdbc:postgresql://db:5432/postgres
password: Access/fedora/6
application:
bucket:
name: moood-app
I tried to search if there was a image of a spring project that I could use but i did'nt find one that can help me.
I tried to find a way to set a default jdbc url for the spring container but didn't find it.
I hope to find a way to set the connexion between the containers
You can pass the value via environment. Something like this:
services:
app_service:
container_name: app_service
build: .
ports:
- "8080:8080"
depends_on:
- postgresql
networks:
- net
environment:
SPRING_DATASOURCE_HIKARI_JDBC_URL: jdbc:postgresql://db:5432/postgres

Cant see plugin, user and project lists in rundeck

Hey guys im just installed rundeck 3.4.9 via docker-compose and after it i cant see the list of installed plugins, the page is refreshing endlessly - same with project list and with user list.
Here is my docker-compose file:
version: '3'
services:
rundeck:
image: rundeck/rundeck:3.4.9
tty: true
volumes:
- data:/home/rundeck/server/data
ports:
- 4440:4440
volumes:
data:
here is what i see in browser:
here what i see in docker-compose logs:
so no errors here, how can i fix this issue ?
In your docker-compose definition add the RUNDECK_GRAILS_URL with the proxy-defined URL for your Rundeck instance and RUNDECK_SERVER_FORWARDED with a true value.
I made a basic example using NGINX as a reverse proxy.
version: "3"
services:
rundeck:
image: rundeck/rundeck:3.4.9
ports:
- 4440:4440
environment:
RUNDECK_GRAILS_URL: http://your_proxy_exit_url_for_rundeck
RUNDECK_SERVER_FORWARDED: "true"
nginx:
image: nginx:alpine
volumes:
- ./config/nginx.conf:/etc/nginx/conf.d/default.conf:ro
ports:
- 80:80
(NGINX conf file referenced on the volumes section):
server {
listen 80 default_server;
server_name rundeck-cl;
# default rundeck location is the root
location / {
# took from default rundeck conf
proxy_pass http://rundeck:4440;
}
}
Take a look at this.

Error while Connecting to a mongo server from a spring boot application when running in a docker locally

I built a REST API using spring boot frame work. In the application I am trying to connect to mongo servers which I am successfully connected to while running in an IDE.
But when I try to run it in a docker I am facing the below issue.
Please help me solve it.
com.mongodb.MongoSocketException: qa-***mongo02.aws.*****.local: Name or service not known
Sharing my docker-compose.yml
Hope this helps.
version: "3.7"
services:
playground_spring_test1_java:
container_name: playground_spring_test1_java
build:
context: ./demo
dockerfile: Dockerfile
stdin_open: true
# env_file:
# - ./dev.env
tty: true
volumes:
- "./demo:/app"
ports:
- 80:8080
playground_spring_test1_mongo:
container_name: playground_spring_test1_mongo
image: mongo
volumes:
- playground_spring_test1_mongo_data:/data/db
ports:
- 27017:27017
volumes:
playground_spring_test1_mongo_data:
Im using MongoTemplate and my application.properties is-
spring.data.mongodb.uri=mongodb://playground_spring_test1_mongo:27017/?authSource=admin

Accessing postgres data in docker-compose network

I'm having trouble accessing a database created from a docker-compose file.
Given the following compose file, I should be able to connect to it from java using something like:
jdbc:postgresql://eprase:eprase#database:7000/eprase
However, the connection is rejected. I can't even use PGAdmin to connect it using the same details to create a new server.
I've entered the database container and ran psql commands to verify that the eprase user and database have been created according to postgres Docker documentation, everything seems fine. I can't tell if the problem is within the database container or something I need to change in the compose network.
The client & server services can largely be ignored, the server is a java based web API and the client is an Angular app.
Compose file:
version: "3"
services:
client:
image: eprase/client:latest
build: ./client/eprase-app
networks:
api:
ports:
- "5000:80"
tty: true
depends_on:
- server
server:
image: eprase/server:latest
build: ./server
networks:
api:
ports:
- "6000:8080"
depends_on:
- database
database:
image: postgres:9
volumes:
- "./database/data:/var/lib/postgresql/data"
environment:
- "POSTGRES_USER=eprase"
- "POSTGRES_PASSWORD=eprase"
- "POSTGRES_DB=eprase"
networks:
api:
ports:
- "7000:5432"
restart: unless-stopped
pgadmin:
image: dpage/pgadmin4:latest
environment:
- "PGADMIN_DEFAULT_EMAIL=admin#eprase.com"
- "PGADMIN_DEFAULT_PASSWORD=eprase"
networks:
api:
ports:
- "8000:80"
depends_on:
- database
networks:
api:
The PostgreSQL database is listening on container port 5432. The 7000:5432 line is mapping host port 7000 to container port 5432. That allows you to connect to the database on port 7000. But, your services on a common network (api) should communicate with each other via the container ports.
So, from the perspective of the containers for the client and server services, the connection string should be:
jdbc:postgresql://eprase:eprase#database:5432/eprase

How can I call Kibana using zuul

I have multiple services say Node-Service running on docker. Along with that, I have EFK Stack also running as a Docker Container.
The Node-Services are getting register on Eureka and getting called from the external network using Api-Gateway (Zuul).
My question is
How can I call Kibana (Service among EFK) using zuul routes?
Is it possible to register Kibana on Eureka ??
Here Is my docker-compose to run EFK
version: '2'
services:
elasticsearch:
image: elasticsearch
expose:
- 9200
ports:
- "9200:9200"
fluentd:
build: ./fluentd
volumes:
- ./fluentd/conf:/fluentd/etc
links:
- "elasticsearch"
ports:
- "24224:24224"
- "24224:24224/udp"
kibana:
image: kibana
links:
- "elasticsearch"
ports:
- "9201:5601"
Below is the snippt for docker-ps
Please Suggest the solution