i have a simple spring cloud project,and it contains 4 services:
config:8888
registry(eureka):8761
gateway(zuul):8080
service-1:9527
enter image description here
the project has no problem if deployed in localhost,
i can successfully fetch service-1's api by zuul without docker:
http://localhost:8080/service-1/test
but when i deployed with docker,
it throws error: Caused by: java.lang.RuntimeException: org.apache.http.conn.HttpHostConnectException: Connect to registry:9527 [registry/172.21.0.4] failed: Connection refused (Connection refused)
i can only fetch with service-1's api
http://localhost:9527/test
PS: the two services(gateway,service-1) has been success registry to eureka
here is my docker-compose yml :
version: '3'
services:
config:
build: ./config
ports:
- "8888:8888"
registry:
build: ./registry
ports:
- "8761:8761"
depends_on:
- config
environment:
- SPRING_PROFILES_ACTIVE=prd
gateway:
build: ./gateway
depends_on:
- config
links:
- registry
- service-1
ports:
- "8080:8080"
environment:
- SPRING_PROFILES_ACTIVE=prd
service-1:
build: ./service-1
ports:
- "9527:9527"
depends_on:
- config
links:
- registry
environment:
- SPRING_PROFILES_ACTIVE=prd
can anyone help me?
i have solved this issue , i forgot add #EnableDiscoveryClient on gateway main class,and cover the eureka instance hostname
Related
Hi I'm new to using docker for development. I'm trying to communicate from frontend (react) to the backend (express.js) here.
I have enabled cors as well, I'm getting an error saying net::ERR_NAME_NOT_RESOLVED when trying to fetch from the back end using the url http://backend:4001,
but it's working when I use the docker internal IPAddress, like: http://172.18.0.3:4001.
Following is my docker-compose.yml file.
Please advise on getting this working, thanks.
version: "3"
services:
backend:
build: ./api
volumes:
- ./api:/usr/src/api
ports:
- 6002:4001
depends_on:
- database
database:
image: mongo:4.0.15-xenial
ports:
- 27018:27017
frontend:
build: ./app
volumes:
- ./app:/usr/src/app
ports:
- 6001:3000
links:
- backend
depends_on:
- backend
It will not work, because your browser(internet client) is not part of docker stack network, you have to configure you frontend service to connect to http://localhost:6002 instead of http://backend:4001
I am using eureka container but unfortunately it is not working properly.
Docker-compose.yaml
configserver:
image: 1.2.3.4:1234/configserver
container_name: configserver
ports:
- 8888:8888
volumes:
- /tmp/logs:/tmp/logs
env_file:
- ./docker.env
eureka:
container_name: eureka
ports:
- 8761:8080
volumes:
- /tmp/logs:/tmp/logs
env_file:
- ./docker.env
image: netflixoss/eureka:1.3.1
restart: always
depends_on:
- configserver
Logs of Container-
WARN com.netflix.discovery.DiscoveryClient:1570 [localhost-startStop-1]
[makeRemoteCall] Can't get a response from localhost:8080/eureka/v2/apps
ERROR com.netflix.discovery.DiscoveryClient:1432 [localhost-startStop-1] [makeRemoteCall] Can't contact any eureka nodes - possibly a security group issue?
ERROR com.netflix.discovery.DiscoveryClient:1033 [localhost-startStop-1] [fetchRegistry] DiscoveryClient_EUREKA/4ae83dcdde1a - was unable to refresh its cache! status = java.net.SocketTimeoutException: Read timed out
I used different image. Instead of netflixoss/eureka:1.3.1 I use eureka. It works for me.
I am new to the Docker World.I have got my db and server connected. Now i want to connect my frontend with server. I an unable to use network mode with link. Without using network mode, i am unable to view my frontend site on localhost:8080.
How can i connect my front and server?
version: '2.2'
services:
front:
build: ../Devops/operations-portal
ports:
- "127.0.0.1:8080:8080"
network_mode: "host"
volumes:
- ../Devops/operations-portal
links:
- server
server:
build: ../Devops/data-mining-backend
ports:
- "5000:5000"
volumes:
- ../Devops/data-mining-backend/:/app
links:
- db
db:
image: mongo:3.6.5
ports:
- "27017:27017"
volumes:
- '../database:/data/db'
command: mongod --smallfiles --logpath=/dev/null # --quiet
I'm a very beginner in docker world, and I'm not able to make two containers communicate using docker compose.
I have two containers:
Service Registry: a simple spring boot application using Netflix Eureka to implement a service registry feature.
API Gateway: a simple spring boot application using Netflix Zuul. This application will try periodically to be registered into the Service Registry application by connecting to a given URL
All work fine without docker !!
And now with docker-compose, the gateway is not able to find the Eureka server URL.
docker-compose.yml file:
version: '3.5'
services:
gateway:
build:
context: ../robots-store-gateway
dockerfile: Dockerfile
image: robots-store-gateway
ports:
- 8000:8000
networks:
- robots-net
serviceregistry:
build:
context: ../robots-sotre-serviceregistry
image: robots-sotre-serviceregistry
ports:
- 8761:8761
networks:
- robots-net
networks:
robots-net:
name: custom_network
driver: bridge
The application.yml file of the gateway is:
eureka:
client:
service-url:
default-zone: http://serviceregistry:8761/eureka/
I receive this exception:
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException:
Connection refused (Connection refused)
I tried different ways to configure the Eureka client but no way !! it doesn't work.
Thanks in advance.
I don't exactly why !!! But finally, this works for me:
version: '3.5'
services:
gateway:
container_name: gateway
build:
context: ../robots-store-gateway
dockerfile: Dockerfile
image: robots-store-gateway
ports:
- 8000:8000
hostname: gateway
environment:
eureka.client.serviceUrl.defaultZone: http://serviceregistry:8761/eureka/
serviceregistry:
container_name: serviceregistry
build:
context: ../robots-sotre-serviceregistry
image: robots-sotre-serviceregistry
ports:
- 8761:8761
hostname: serviceregistry
environment:
eureka.client.serviceUrl.defaultZone: http://serviceregistry:8761/eureka/
You didn't set the container name.
Link
And the url or ip should replace to container name.
Example:
mongodb://{container_name}:27017
I'm trying to setup a CD/CI build environment with docker compose.
I have a jenkins container, a sonar container and an archiva container. The problem is, my jenkins cannot connect to sonar and archiva.
I tried linking multiple containers together or joining them in the same network, but still no success.
In jenkins, I get the following error:
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8081 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
This is my docker-compose file.
version: '2'
volumes:
data-jenkins:
driver: 'local'
data-postgres:
driver: 'local'
data-sonarqube-conf:
driver: 'local'
data-sonarqube-data:
driver: 'local'
data-archiva:
driver: 'local'
services:
jenkins:
image: 'jenkins'
ports:
- '8080:8080'
restart: 'always'
volumes:
- 'data-jenkins:/var/jenkins_home'
links:
- 'sonarqube:sonarqube'
postgres:
image: 'postgres:9.6.1'
environment:
- 'POSTGRES_USER=postgres'
- 'POSTGRES_PASSWORD=postgres'
ports:
- '5432:5432'
restart: 'always'
volumes:
- 'data-postgres:/var/lib/postgresql/data'
sonarqube:
image: 'sonarqube'
depends_on:
- 'postgres'
ports:
- '9000:9000'
links:
- 'postgres:postgres'
environment:
- 'SONARQUBE_JDBC_URL=jdbc:postgresql://postgres:5432/'
- 'SONARQUBE_JDBC_USERNAME=postgres'
- 'SONARQUBE_JDBC_PASSWORD=postgres'
volumes:
- 'data-sonarqube-data:/var/lib/sonarqube/data'
- 'data-sonarqube-conf:/var/lib/sonarqube/conf'
archiva:
image: 'xetusoss/archiva'
ports:
- '8081:8080'
volumes:
- 'data-archiva:/var/archiva'
environment:
- 'SSL_ENABLED=false'
It seems the Jenkins container is living in a seperate environment. Does anyone how can i join all the environments together? Been struggling with this problem for almost a week now
To reference your sonarqube container from Jenkins use sonarqube:9000 docker will translate your service name sonarqube to the ip of that container.
I would also recommend using different networks rather than links to connect your containers.
This is because the ping is going to sonarqube.