Trying to start eureka and config server with docker container - docker

I'm a new learner of docker. Trying to start the eureka server and configure the server but the config server gives an error: Cannot execute the request on any known server at and due to this error I can't start other microservice.
application.yml(eureka service)
server:
port: 5002
eureka:
client:
service-url:
defaultZone: http://localhost:5002/eureka/
register-with-eureka: false
fetch-registry: false
application.yml(config microservice)
server:
port: 9095
spring:
application:
name: config-server
profiles:
active:
- native
cloud:
config:
server:
native:
search-locations:
- classpath:/
eureka:
instance:
hostname: localhost
port: 5002
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://${eureka.instance.hostname}:${eureka.instance.port}/eureka/
and having two separate dockerfiles for the same in which FROM, ADD, EXPOSE, ENTRYPOINT is used

Related

Traefik V2 docker provider path /ws routing to external websocket server

Stack:
serverX
docker
traefik
x-site.com
redirect :80->:443
https://x-site.com/* -> x-site docker container
wss://x-site.com/ws proxy -> ws://external.websocket.com:8083/ws HOW TO?
y-site.com
...
external.websocket.com - works perfectly with all kinds of mqtt,ws clients, except web
software: emqx
listens: ws:8083 mqtt:1883
protocol: ws, mqtt
proxy protocol support: on
docker-compose.yml
version: '3.7'
services:
router:
container_name: router
image: traefik:v2.6
restart: on-failure:5
ports:
- target: 80
published: 80
mode: host
- target: 443
published: 443
mode: host
- target: 8080
published: 8080
mode: host
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./router:/etc/traefik
x-site:
container_name: x-site
image: backend
restart: on-failure:5
env_file:
- /.default.env
- /.server.env
- /root/env/x-site.env
labels:
traefik.enable: true
traefik.http.routers.x-site.rule: Host(`x-site.com`)
traefik.http.routers.x-site.entrypoints: web,websecure
traefik.http.routers.x-site.tls: true
# tried service loadbalancer and etc
# traefik.http.routers.ws_x-site.rule: Host(`x-site.com`) && PathPrefix(`/ws`)
# traefik.http.routers.ws_x-site.entrypoints: websecure
# traefik.http.routers.ws_x-site.service: websocket_x-site
# traefik.http.services.websocket_x-site.loadBalancer.server.url: ws://external.websocket.com:8083/ws
traefik.yaml
api:
insecure: true
dashboard: true
entryPoints:
web:
address: ":80"
http:
redirections:
entryPoint:
to: websecure
scheme: https
permanent: true
transport:
respondingTimeouts:
readTimeout: 10
writeTimeout: 10
idleTimeout: 10
lifeCycle:
requestAcceptGraceTimeout: 5
graceTimeOut: 5
websecure:
address: ":443"
transport:
respondingTimeouts:
readTimeout: 300
writeTimeout: 3600
idleTimeout: 180
lifeCycle:
requestAcceptGraceTimeout: 30
graceTimeOut: 30
providers:
docker:
endpoint: unix:///var/run/docker.sock
exposedByDefault: false
file:
filename: /etc/traefik/cert.yaml
log:
level: ERROR

docker nginx load balancer connect() failed (111: Connection refused) while connecting to upstream

I'm trying to load balance a simple Nodejs app with 3 instances using docker-compose & nginx. This configuration works on my local machine (windows laptop) but doesn't seem to work on EC2 server.
nginx.conf
http {
upstream all {
server nodeapp1:4100;
server nodeapp2:4200;
server nodeapp3:4300;
}
server {
listen 8080;
location / {
proxy_pass http://all/;
}
}
}
events { }
docker-compose.yml
version: '3'
services:
lb:
image: nginx
volumes:
- ./nginxproxy/nginx.conf:/etc/nginx/nginx.conf
ports:
- "3000:8080"
nodeapp1:
image: nodeapp
environment:
- PORT=4100
ports:
- "4100:4100"
nodeapp2:
image: nodeapp
environment:
- PORT=4200
ports:
- "4200:4200"
nodeapp3:
image: nodeapp
environment:
- PORT=4300
ports:
- "4300:4300"
I'm new to docker. I'm surprised why this works locally but does not work on EC2 instance. The load balancer was able to resolve the url correctly but it still says connection refused.
Error:
2022/02/28 20:00:22 [error] 33#33: *9 connect() failed (111: Connection refused) while
connecting to upstream, client: 62.113.237.40, server: , request: "GET / HTTP/1.1",
upstream: "http://172.121.0.5:4100/", host: "18.121.121.23:3000"
For me service name or ip address not worked, only work put the gateway IP of network, for default bridge is 172.17.0.1.
In the servers put the (gateway ip):(port of container) and with this haproxy connects with success.
My example of custom network with fixed ips and gateway:
---- nginx config
upstream loadbalancer {
server 172.17.0.1:8001 weight=5;
server 172.17.0.1:8002 weight=5;
}
----- haproxy config similar
backend be_pe_8545
mode http
balance roundrobin
server p1 172.20.0.254:18545 check inter 10s
server p2 172.20.0.254:28545 check inter 10s
----- docker app / network
docker_app: ...
networks:
public_network:
ipv4_address: 172.20.0.50
public_network:
name: public_network
driver: bridge
ipam:
driver: default
config:
- subnet: 172.20.0.0/24
gateway: 172.20.0.254

Exception trying to connect a service in a docker container to eureka in a docker container

I am trying to connect a eureka client in one docker container to a eureka server in another docker container.
I am trying to connect via the service name set up in my
In my docker docker-compose.yaml
services:
eureka-server:
image: eurekaservice
hostname: eureka-server
container_name: eurekahost
ports:
- "8761:8761"
In my eureka properties file I have
spring.application.name=eureka-service
server.port=8761
eureka.client.registerWithEureka = false
eureka.client.fetchRegistry = false
eureka.instance.hostname=eurekahost
eureka.client.serviceUrl.defaultZone = http://eurekahost:8761/eureka
in my eureka client properties file I have
server.port=8080
spring.application.name=user-service
eureka.client.registerWithEureka = true
eureka.client.fetchRegistry = true
eureka.client.serviceUrl.defaultZone = http://eurekahost:8761/eureka
eureka.client.instance.preferIpAddress = false
eureka.instance.hostname= eurekahost
I run the Eureka with docker-compose up
Then i start up the client service with
docker run -p 8083:8080 bankuser
i get the following exception
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:156)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:376)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
Cant figure out what I am missing.
Updated properties to yml file for ease of reading
application.yml for eureka server
server:
port=8761
spring:
application: eureka-service
eureka:
instance:
hostname: eurekahost
client:
validateCertificates: false
registerWithEureka: false
fetchRegistry: false
healthcheck:
enabled: true
serviceUrl:
defaultZone: http://eurekahost:8761/eureka
application.yml for eureka client
server:
port=8080
spring:
application: name=user-service
eureka:
instance:
hostname: eurekahost
client:
validateCertificates: true
registerWithEureka: true
fetchRegistry: true
healthcheck:
enabled: true
serviceUrl:
defaultZone: http://eurekahost:8761/eureka
instance:
preferIpAddress: false
If

Traefik v2 reverse proxy to a local server outside Docker

I have a simple server written in Python that listens on port 8000 inside a private network (HTTP communication). There is now a requirement to switch to HTTPS communications and every client that sends a request to the server should get authenticated with his own cert/key pair.
I have decided to use Traefik v2 for this job. Please see the block diagram.
Traefik runs as a Docker image on a host that has IP 192.168.56.101. First I wanted to simply forward a HTTP request from a client to Traefik and then to the Python server running outside Docker on port 8000. I would add the TLS functionality when the forwarding is running properly.
However, I can not figure out how to configure Traefik to reverse proxy from i.e. 192.168.56.101/notify?wrn=1 to the Python server 127.0.0.1:8000/notify?wrn=1.
When I try to send the above mentioned request to the server (curl "192.168.56.101/notify?wrn=1") I get "Bad Gateway" as an answer. What am I missing here? This is the first time that I am in contact with Docker and reverse proxy/Traefik. I believe it has something to do with ports but I can not figure it out.
Here is my Traefik configuration:
docker-compose.yml
version: "3.3"
services:
traefik:
image: "traefik:v2.1"
container_name: "traefik"
hostname: "traefik"
ports:
- "80:80"
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./traefik.yml:/traefik.yml:ro"
traefik.yml
## STATIC CONFIGURATION
log:
level: INFO
api:
insecure: true
dashboard: true
entryPoints:
web:
address: ":80"
providers:
docker:
watch: true
endpoint: "unix:///var/run/docker.sock"
file:
filename: "traefik.yml"
## DYNAMIC CONFIGURATION
http:
routers:
to-local-ip:
rule: "Host(`192.168.56.101`)"
service: to-local-ip
entryPoints:
- web
services:
to-local-ip:
loadBalancer:
servers:
- url: "http://127.0.0.1:8000"
First, 127.0.0.1 will resolve to the traefik container and not to the docker host. You need to provide a private IP of the node and it needs to be accessible form the traefik container.
There is some workaround to make proxy to localhost:
change 127.0.0.1 to IP of docker0 interface
It should be 172.17.0.1
and then try to listen your python server on all interfaces (0.0.0.0)
if you use simple python http server nothing change... on default it listen on all interfaces

axios ECONNREFUSED when requesting in a docker-compose service behind nginx reverse proxy

I have two docker-compose setup, the main service is an SPA containing:
nginx proxy for a wordpress on port 80
wordpress + mysql
expressjs for serving a react app port 6000
This runs behind another docker-compose which is basically an nginx-reverse proxy.
The SPA manages to serve website and connects to backend API via reverse proxy just fine. However, when I try to make a separate https request to the backend api from the server.js I get this message:
{ Error: connect ECONNREFUSED 127.0.0.1:443
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1121:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 443 }
And it's not just axios, plain wget to the backend url gives me connection refused as well.
A sample for said request:
axios.put('/wc/v3/orders/934', {
status: "completed"
},{
withCredentials:true,
auth: {
username: process.env.REACT_APP_WC_ADMIN_CK_KEY,
password: process.env.REACT_APP_WC_ADMIN_CS_KEY
}
}).then(function (response) {
console.log(`ok`);
}).catch(function (error) {
console.log(error);
});
Any one knows what might be the problem here?
If you have multiple docker-compose environments, then each brings up its own network by default. You want to share the network between the two to allow for the services in one environment to communicate to the other.
# spa/docker-compose.yml
version: '2'
services:
spa:
...
networks:
- app-net
networks:
app-net:
driver: bridge
.
# express/docker-compose.yml
version: '2'
services:
api:
...
networks:
- spa_app-net
networks:
spa_app-net:
external: true

Resources