Exception while running docker compose for rabbitmq - docker-compose

2021-02-10 16:00:04.261 INFO 1 --- [ main] c.i.m.n.NamingServerApplication : Started NamingServerApplication in 20.797 seconds (JVM running for 21.293) naming-server_1
2021-02-10 16:00:04.305 INFO 1 --- [ Thread-10] e.s.EurekaServerInitializerConfiguration : Started Eureka Server zipkin-server_1
2021-02-10 16:00:05.027 WARN [/] 1 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'armeriaServer' defined in com.linecorp.armeria.spring.ArmeriaAutoConfiguration: Unsatisfied dependency expressed through method 'armeriaServer' parameter 5;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'serverConfigurator' defined in zipkin2.server.internal.ZipkinHttpConfiguration: Unsatisfied dependency expressed through method 'serverConfigurator' parameter 2;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'zipkin2.server.internal.health.ZipkinHealthController': Unsatisfied dependency expressed through constructor parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rabbitMq' defined in zipkin2.server.internal.rabbitmq.ZipkinRabbitMQCollectorConfiguration: Invocation of init method failed;
nested exception is java.io.UncheckedIOException: Unable to establish connection to RabbitMQ server: rabbitmq: Try again zipkin-server_1
rabbitmq:
image : rabbitmq:3.5.3-management
mem_limit: 300m
ports:
- "5672:5672"
- "15672:15672"
environment:
RABBIT_URI : amqp://guest:guest#rabbitmq:5672
zipkin-server:
image : openzipkin/zipkin:2.23
mem_limit: 300m
ports:
- "9411:9411"

I had faced similar issue and it was fixed by adding restart: always key-value for zipkin-server. You can specify the RABBIT_URI for zipkin-server, but rabbitmq might not require it to be specified. And if you are planning to save the traces in mq in case zipkin is down, adding this dependency to zipkin-server can help:
depends_on:
- rabbitmq
So the .yaml snippet will look like:
rabbitmq:
image: rabbitmq:3.5.3-management
mem_limit: 300m
ports:
- "5672:5672"
- "15672:15672"
zipkin-server:
image: openzipkin/zipkin:2.23
mem_limit: 300m
ports:
- "9411:9411"
environment:
RABBIT_URI: amqp://guest:guest#rabbitmq:5672
depends_on:
- rabbitmq
restart: always

You can make this a little easier if you write down what you are trying to achieve and properly format the error and the yaml. If you do it you will have a better chance to spot this in the last line:
java.io.UncheckedIOException: Unable to establish connection to RabbitMQ server: rabbitmq: Try again zipkin-server_1
This means that the application is not able to connect to the host, try to update the host and use localhost if you are outside of the docker network i.e.: on the host and use the container_name if you are inside. I would also suggest defining the container_name, here is an example for zipkin and here is one for rabbit
Btw, I'm not sure what is the intention with RABBIT_URI inside of the rabbitmq service in your docker-compose.

Related

RabbitMQ - How to use custom configuration file in docker-compose?

I'm a beginner in using rabbitmq and docker-compose.
I cannot figure out how to use my own config file... At start, rabbitmq service keeps exiting with the error:
rabbitmq1 | 2022-06-17 14:50:43.578486+00:00 [error] <0.130.0> Failed to load advanced configuration file "/etc/rabbitmq/rabbitmq.config": 1: syntax error before:
My conf file is the following one (myrabbit.conf)
consumer_timeout = 10000
The file is in the same directory then the docker-compose file which is:
version: "3"
services:
rabbitmq:
image: rabbitmq:3-management
container_name: rabbitmq1
hostname: 'rabbitmq'
ports:
- "5672:5672"
- "15672:15672"
volumes:
- ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/mnesia/
- ./myrabbit.conf:/etc/rabbitmq/rabbitmq.config #problematic line I guess...
restart: always
Other test:
Instead of this :
- ./myrabbit.conf:/etc/rabbitmq/rabbitmq.config
When I try this:
- myrabbit.conf:/etc/rabbitmq/rabbitmq.config
I get the following error:
ERROR: Named volume "myrabbit.conf:/etc/rabbitmq/rabbitmq.config:rw" is used in service "rabbitmq" but no declaration was found in the volumes section.
I finally made it works.
Here is what I did:
Create a directory called "rabbitmq" in the same directory than the docker-compose.yml file
In that new directory, create the file: rabbitmq.conf (to be confirmed, but it appears that it must be that name).
Adapt the docker-compose.yml file as following:
version: "3"
services:
rabbitmq:
image: rabbitmq:3-management
container_name: rabbitmq
hostname: 'rabbitmq'
ports:
- "5672:5672"
- "15672:15672"
volumes:
- ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/mnesia/
- ./rabbitmq/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf
restart: always
During the boot, you should see:
Which means that rabbitmq service is well using the custom conf file.
Hope it will help others...

How to find Cassandra startup failure cause

I'm trying to run Cassandra in Docker. Previously that was fine (unfortunately I used latest image). Now when I run compose with different versions it never succeeds. Sometimes I see in logs that startup compete, sometimes now. Every time it ends up with cassandra exited with code 137. I can find no errors in logs. How can I diagnose the problem?
Here's my compose file. I tried to switch between 3.0.24, 3.11, 4 and 4.0.1 versions with no luck.
version: '3'
services:
cassandra:
image: cassandra:3.0.24
container_name: cassandra
ports:
- '7000:7000'
- '9042:9042'
- '9142:9142'
volumes:
- ./cassandra/cassandra-data:/var/lib/cassandra
environment:
- CASSANDRA_SEEDS=cassandra
- CASSANDRA_PASSWORD_SEEDER=yes
- CASSANDRA_PASSWORD=cassandra
networks:
- default-dev-network
networks:
default-dev-network:
external: true
UPDATE
Here's a logs example. But it varies from run to run.
INFO 16:01:43 Node /172.18.0.5 state jump to NORMAL
INFO 16:01:43 Waiting for gossip to settle before accepting client requests...
INFO 16:01:51 No gossip backlog; proceeding
INFO 16:01:51 Netty using native Epoll event loop
INFO 16:01:51 Using Netty Version: [netty-buffer=netty-buffer-4.0.44.Final.452812a, netty-codec=netty-codec-4.0.44.Final.452812a, netty-codec-haproxy=netty-codec-haproxy-4.0.44.Final.452812a, netty-codec-http=netty-codec-http-4.0.44.Final.452812a, netty-codec-socks=netty-codec-socks-4.0.44.Final.452812a, netty-common=netty-common-4.0.44.Final.452812a, netty-handler=netty-handler-4.0.44.Final.452812a, netty-tcnative=netty-tcnative-1.1.33.Fork26.142ecbb, netty-transport=netty-transport-4.0.44.Final.452812a, netty-transport-native-epoll=netty-transport-native-epoll-4.0.44.Final.452812a, netty-transport-rxtx=netty-transport-rxtx-4.0.44.Final.452812a, netty-transport-sctp=netty-transport-sctp-4.0.44.Final.452812a, netty-transport-udt=netty-transport-udt-4.0.44.Final.452812a]
INFO 16:01:51 Starting listening for CQL clients on /0.0.0.0:9042 (unencrypted)...
INFO 16:01:51 Not starting RPC server as requested. Use JMX (StorageService->startRPCServer()) or nodetool (enablethrift) to start it
INFO 16:01:51 Startup complete
The reason was memory or CPU issue. After adding resources it runs, but not every time. Playing with CPUs and memory somehow helps but didn't bring reliable result.
Here's full compose file
version: '3'
services:
cassandra:
image: cassandra:3.0.24
container_name: cassandra
deploy:
replicas: 1
resources:
limits:
cpus: '2'
memory: 2G
ports:
- '7000:7000'
- '9042:9042'
- '9142:9142'
volumes:
- ./cassandra/cassandra-data:/var/lib/cassandra
environment:
- CASSANDRA_SEEDS=cassandra
- CASSANDRA_PASSWORD_SEEDER=yes
- CASSANDRA_PASSWORD=cassandra
networks:
- default-dev-network
networks:
default-dev-network:
external: true

Docker-compose does not recognice Postgres Host of SpringBoot App

I'am trying to use docker-compose with a springboot app(uses JPA) and a postgres database, I am kinda new using docker and I don't know what I am doing wrong.
Problem
When I build the springboot app, if I change
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres(code that works) to host it in postgres container, spring.datasource.url=jdbc:postgresql://postgres:5432/postgres.
It throws me a PSQLException caused by: java.net.UnknownHostException: postgres.(More details below)
application.properties
server.port = 8080
## default connection pool
spring.datasource.hikari.connectionTimeout=20000
spring.datasource.hikari.maximumPoolSize=5
## PostgreSQL
spring.datasource.url=jdbc:postgresql://postgres:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.jpa.hibernate.ddl-auto=create
Exception
2020-06-22 19:07:10.597 INFO 16088 --- [ main] c.a.a.AnnotationToolApplicationTests : Starting AnnotationToolApplicationTests on DESKTOP-P1E07PA with PID 16088 (started by Pedro in C:\Users\Pedro\git\tfg\annotation-tool\annotation-tool)
2020-06-22 19:07:10.598 INFO 16088 --- [ main] c.a.a.AnnotationToolApplicationTests : No active profile set, falling back to default profiles: default
2020-06-22 19:07:11.584 INFO 16088 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-06-22 19:07:11.719 INFO 16088 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 120ms. Found 3 JPA repository interfaces.
2020-06-22 19:07:12.235 INFO 16088 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-06-22 19:07:12.572 INFO 16088 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-06-22 19:07:12.746 INFO 16088 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.4.10.Final}
2020-06-22 19:07:13.002 INFO 16088 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-06-22 19:07:13.434 INFO 16088 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-06-22 19:07:16.873 ERROR 16088 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:292) ~[postgresql-42.2.9.jar:42.2.9]
...
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126) ~[surefire-booter-2.22.2.jar:2.22.2]
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418) ~[surefire-booter-2.22.2.jar:2.22.2]
Caused by: java.net.UnknownHostException: postgres
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184) ~[na:1.8.0_222]
docker-compose.yml
version: '3'
services:
# SpringBoot App
postgres:
image: "postgres:9.6-alpine"
ports:
- 5432:5432
volumes:
- apiDB:/var/lib/postgresql/data
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
api:
build: ./annotation-tool
ports:
- 8080:8080
depends_on:
- postgres
client:
container_name: client-container
build: ./client
ports:
- 8081:8081
volumes:
apiDB:
Api Dockerfile
FROM maven:3.6.1-jdk-8-slim AS build
RUN mkdir -p /workspace
WORKDIR /workspace
COPY pom.xml /workspace
COPY src /workspace/src
RUN mvn -f pom.xml clean package
FROM openjdk:8
COPY --from=build /workspace/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","app.jar"]
Things that I think that happened/ tried
Maybe the DNS is not working, but I don't know how I can solve it
I tried differents docker-compose and Dockerfiles and it doesn't work
If I run the docker-compose the postgres container is created succesfully
I tried changing the url host to postgres-backend as my container was named that way
I tried by using links between my components.
I think springboot application is finding postgres db before its container is getting up...you can add depends_on property in springboot container ..so the postgres container starts first then springboot
version: '3'
services:
# SpringBoot App
postgres:
image: "postgres:9.6-alpine"
ports:
- 5432:5432
volumes:
- apiDB:/var/lib/postgresql/data
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
api:
build: ./annotation-tool
ports:
- 8080:8080
depends_on:
- postgres
client:
container_name: client-container
build: ./client
ports:
- 8081:8081
volumes:
apiDB:
I don't know if I am thinking to simple right know but all container of your docker-compose file run on the same host, right? So then your url should point to jdbc:postgresql://localhost:5432/postgres.
I don't know if you already solved the problem but have you tried to use a bridge network on the setup?
version: '3'
services:
# SpringBoot App
postgres:
image: "postgres:9.6-alpine"
ports:
- 5432:5432
volumes:
- apiDB:/var/lib/postgresql/data
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
networks:
- database-network
api:
build: ./annotation-tool
ports:
- 8080:8080
depends_on:
- postgres
networks:
- database-network
client:
container_name: client-container
build: ./client
ports:
- 8081:8081
networks:
database-network:
driver: bridge
external: false
volumes:
apiDB:

Getting error messages when running the docker-compose up command on Linux mint

Using the Linux terminal, I'm trying to run the command 'docker-compose up' but instead I get a lot of errors. The following is what is contained in my docker-compose file:
version: "3.3"
services:
postgres:
image: postgres:9.6
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=pass
- POSTGRES_DB=db
volumes:
- ./gitignore/postgresql:/var/lib/postgresql/data
ports:
- 5432:5432
adminer:
image: adminer
restart: always
ports:
- 8080:8080
and when I run the command on the terminal, these are the errors that I encounter:
~/Desktop/dockerPostgreSQL/docker-composer$ docker-compose up
Creating network "dockercomposer_default" with the default driver
Creating dockercomposer_adminer_1 ...
Creating dockercomposer_postgres_1 ...
Creating dockercomposer_adminer_1
Creating dockercomposer_adminer_1 ... error
ERROR: for dockercomposer_adminer_1 Cannot start service adminer: driver failed programming external connectivity on endpoint dockercomposer_adminer_1 (5d1ce2f6a1e6c4600e8482e87be3e60547955cdadbe64a2fb82facca14491291): Bind for 0.0.0.0:808Creating dockercomposer_postgres_1 ... error
ERROR: for dockercomposer_postgres_1 Cannot start service postgres: driver failed programming external connectivity on endpoint dockercomposer_postgres_1 (e339a5e928066244eed6f119cec4bb9863376264b58e38242034f20da72c7422): Error starting userland proxy: listen tcp 0.0.0.0:5432: bind: address already in use
ERROR: for adminer Cannot start service adminer: driver failed programming external connectivity on endpoint dockercomposer_adminer_1 (5d1ce2f6a1e6c4600e8482e87be3e60547955cdadbe64a2fb82facca14491291): Bind for 0.0.0.0:8080 failed: port is already allocated
ERROR: for postgres Cannot start service postgres: driver failed programming external connectivity on endpoint dockercomposer_postgres_1 (e339a5e928066244eed6f119cec4bb9863376264b58e38242034f20da72c7422): Error starting userland proxy: listen tcp 0.0.0.0:5432: bind: address already in use
ERROR: Encountered errors while bringing up the project.
Could anyone please assist me with this in as to what I could be doing wrong an what I can do to fix these errors?
A service already use 8080 port.
You have to choose an other one in your docker-compose file (8081 for example) :
ports:
- 8081:8080

Can't up my Eureka Spring REST service in a Docker container

My project consists of a REST service, which is registered in Eureka, also I use Zuul proxy to manage requests as seen in this image. It runs perfectly on my computer in a local way but when I create a docker container for my service, it doesn't start. The steps I followed:
I created a Docker container for each service: Eureka server, Zuul API Gateway, the REST service and my Mysql database.
I get the data of my service from a stored procedure in the database, this conection was tested and it works.
I start all instances with docker-compose, Eureka and database instances remains up but the REST service instance stops abruptly. Zuul not is implemented yet.
The error:
matriculas-ms_1 | org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.eurekaClient' defined in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.netflix.discovery.EurekaClient]: Factory method 'eurekaClient' threw exception; nested exception is java.lang.RuntimeException: Failed to initialize DiscoveryClient!
Here is the docker-compose.yml
version: '3.3'
services:
srclbd:
build: ./srclbd
ports:
- "3307:3306"
expose:
- "3306"
volumes:
- ./srclbd/data:/var/lib/mysql
eureka:
build: ./Eureka
ports:
- "8761:8761"
expose:
- "8761"
matriculas-ms:
build: ./matriculas-ms
ports:
- "3333:3333"
expose:
- "3333"
depends_on:
- srclbd
- eureka
links:
- srclbd
- eureka
environment:
- DATABASE_HOST=srclbd
- EUREKA_HOST=eureka
Eureka's Dockerfile:
FROM java:8
ADD /target/eureka-0.0.1-SNAPSHOT.jar eureka-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java","-jar","eureka-0.0.1-SNAPSHOT.jar"]
REST service Dockerfile:
FROM java:8
ADD /target/matriculas-service-0.0.1-SNAPSHOT.jar matriculas-service- 0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java","-jar","matriculas-service-0.0.1-SNAPSHOT.jar","-Xdebug -Xrunjdwp:server=y,transport=dt_socket,suspend=n"]
Here is my project on github
Which is my error?
Finally I solved my error setting up a separated configuration profile to Docker container like this:
spring:
profiles: container
application:
name: matriculas-ms
jpa:
hibernate:
ddl-auto: none
datasource:
url: jdbc:mysql://srclbd:3306/srcl?useSSL=false&noAccessToProcedureBodies=true
username: root
password: root
initialize: true
eureka:
client:
serviceUrl:
defaultZone: http://eureka:8761/eureka/
server:
port: 1111
Then, I established this profile in the Dockerfile created to my REST service. So, every time it executes the JAR file, it will with the created profile's configuration.
FROM java:8
ADD /target/svcMatriculas.jar svcMatriculas.jar
ENTRYPOINT ["java","-Dspring.profiles.active=container","-jar","svcMatriculas.jar"]
Thanks!