Quarkus can't connect to kafka from inside docker [duplicate] - docker

This question already has answers here:
Connect to Kafka running in Docker
(5 answers)
Closed 1 year ago.
I've created a quarkus service that reads from a bunch of Kstreams, joins them and then post the join result back into a kafka topic.
During development, I was running kafka and zookeeper from inside a docker-compose and then running my quarkus service on dev mode with:
mvn quarkus:dev
At this point, everything was working fine. I'm able to connect to the broker without problem and read/write the Kstreams.
Then I tried to create a docker container that runs this quarkus service, but when the service runs inside the container, it doesn't reach the broker.
I tried several different configs inside my docker-compose, but none worked. It just can't connect to the broker.
Here is my Dockerfile:
####
# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode
#
# Before building the container image run:
#
# mvn package
#
# Then, build the image with:
#
# docker build -f src/main/docker/Dockerfile.jvm -t connector .
#
# Then run the container using:
#
# docker run -i --rm -p 8080:8080 connector
#
# If you want to include the debug port into your docker image
# you will have to expose the debug port (default 5005) like this : EXPOSE 8080 5050
#
# Then run the container using :
#
# docker run -i --rm -p 8080:8080 -p 5005:5005 -e JAVA_ENABLE_DEBUG="true" connector
#
###
FROM docker.internal/library/quarkus-base:latest
ARG RUN_JAVA_VERSION=1.3.8
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en'
USER root
RUN apk update && apk add libstdc++
# Configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size.
ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
#ENV QUARKUS_LAUNCH_DEVMODE=true \
# JAVA_ENABLE_DEBUG=true
# -Dquarkus.package.type=mutable-jar
# We make four distinct layers so if there are application changes the library layers can be re-used
COPY --chown=1001 target/quarkus-app/lib/ ${APP_HOME}/lib/
COPY --chown=1001 target/quarkus-app/*-run.jar ${APP_HOME}/app.jar
COPY --chown=1001 target/quarkus-app/app/ ${APP_HOME}/app/
COPY --chown=1001 target/quarkus-app/quarkus/ ${APP_HOME}/quarkus/
EXPOSE 8080
USER 1001
#ENTRYPOINT [ "/deployments/run-java.sh" ]
And here is my docker-compose:
version: '2'
services:
zookeeper:
container_name: zookeeper
image: confluentinc/cp-zookeeper
ports:
- "2181:2181"
- "2888:2888"
- "3888:3888"
environment:
- ZOOKEEPER_CLIENT_PORT=2181
- ZOOKEEPER_TICK_TIME=2000
networks:
- kafkastreams-network
kafka:
container_name: kafka
image: confluentinc/cp-kafka
ports:
- "9092:9092"
depends_on:
- zookeeper
environment:
- KAFKA_BROKER_ID=1
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
- KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
- KAFKA_AUTO_CREATE_TOPICS_ENABLE=true
- KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1
- KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1
- KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1
- KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS=100
networks:
- kafkastreams-network
connect:
container_name: connect
image: debezium/connect
ports:
- "8083:8083"
depends_on:
- kafka
environment:
- BOOTSTRAP_SERVERS=kafka:29092
- GROUP_ID=1
- CONFIG_STORAGE_TOPIC=my_connect_configs
- OFFSET_STORAGE_TOPIC=my_connect_offsets
- STATUS_STORAGE_TOPIC=my_connect_statuses
networks:
- kafkastreams-network
schema-registry:
image: confluentinc/cp-schema-registry:5.5.0
container_name: schema-registry
ports:
- "8081:8081"
depends_on:
- zookeeper
- kafka
environment:
SCHEMA_REGISTRY_HOST_NAME: schema-registry
SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL: zookeeper:2181
networks:
- kafkastreams-network
kafdrop:
image: obsidiandynamics/kafdrop
container_name: kafdrop
restart: "no"
ports:
- "9001:9000"
environment:
KAFKA_BROKERCONNECT: kafka:29092
JVM_OPTS: "-Xms16M -Xmx48M -Xss180K -XX:-TieredCompilation -XX:+UseStringDeduplication -noverify"
depends_on:
- kafka
- schema-registry
networks:
- kafkastreams-network
connector:
image: connector
depends_on:
- zookeeper
- kafka
- connect
environment:
QUARKUS_KAFKA_STREAMS_BOOTSTRAP_SERVERS: kafka:9092
networks:
- kafkastreams-network
networks:
kafkastreams-network:
name: ks
The error I'm getting is:
2021-08-05 11:52:35,433 WARN [org.apa.kaf.cli.NetworkClient] (kafka-admin-client-thread | connector-18d10d7d-b619-4715-a219-2557d70e0479-admin) [AdminClient clientId=connector-18d10d7d-b619-4715-a219-2557d70e0479-admin] Connection to node -1 (kafka/172.21.0.3:9092) could not be established. Broker may not be available.
Am I missing any config on either the Dockerfile or the docker compose?

I figured out that there were 2 problems:
In my docker-compose, I had to change the property KAFKA_ADVERTISED_LISTENERS to PLAINTEXT://kafka:29092,PLAINTEXT_HOST://kafka:9092
In my quarkus application.properties, I had 2 properties pointing to the wrong place:
quarkus.kafka-streams.bootstrap-servers=localhost:9092
quarkus.kafka-streams.application-server=localhost:9999

Related

Docker ERROR 2002 (HY000): Can't connect to MySQL server on 'db' (115)

i using docker with https://github.com/markshust/docker-magento . when i in step by step try to import db i got error ERROR 2002 (HY000): Can't connect to MySQL server on 'db' (115)
I tried this solution ERROR 2002 (HY000): Can't connect to MySQL server on 'db' (115).
my yml file
## Mark Shust's Docker Configuration for Magento
## (https://github.com/markshust/docker-magento)
##
## Version 41.0.2
## To use SSH, see https://github.com/markshust/docker-magento#ssh
## Linux users, see https://github.com/markshust/docker-magento#linux
## If you changed the default Docker network, you may need to replace
## 172.17.0.1 in this file with the result of:
## docker network inspect bridge --format='{{(index .IPAM.Config 0).Gateway}}'
version: "3"
services:
app:
image: markoshust/magento-nginx:1.18-5
ports:
- "80:8000"
- "443:8443"
volumes: &appvolumes
- ~/.composer:/var/www/.composer:cached
- ~/.ssh/id_rsa:/var/www/.ssh/id_rsa:cached
- ~/.ssh/known_hosts:/var/www/.ssh/known_hosts:cached
- appdata:/var/www/html
- sockdata:/sock
- ssldata:/etc/nginx/certs
extra_hosts: &appextrahosts
## M1 Mac support to fix Docker delay, see #566
- "app:172.17.0.1"
- "phpfpm:172.17.0.1"
- "db:172.17.0.1"
- "redis:172.17.0.1"
- "elasticsearch:172.17.0.1"
- "rabbitmq:172.17.0.1"
## Selenium support, replace "magento.test" with URL of your site
- "magento.test:172.17.0.1"
phpfpm:
image: markoshust/magento-php:7.2-fpm
volumes: *appvolumes
env_file: env/phpfpm.env
db:
image: mariadb:10.1
command: mysqld --innodb_force_recovery=6 --lower_case_table_names=1 --skip-ssl --character_set_server=utf8mb4 --explicit_defaults_for_timestamp
ports:
- "3306:3306"
env_file: env/db.env
volumes:
- dbdata:/var/lib/mysql
redis:
image: redis:6.0-alpine
ports:
- "6379:6379"
elasticsearch:
image: markoshust/magento-elasticsearch:7.9.3-1
ports:
- "9200:9200"
- "9300:9300"
environment:
- "discovery.type=single-node"
## Set custom heap size to avoid memory errors
- "ES_JAVA_OPTS=-Xms1g -Xmx1g"
## Avoid test failures due to small disks
## More info at https://github.com/markshust/docker-magento/issues/488
- "cluster.routing.allocation.disk.threshold_enabled=false"
- "index.blocks.read_only_allow_delete"
rabbitmq:
image: rabbitmq:3.8.22-management-alpine
ports:
- "15672:15672"
- "5672:5672"
volumes:
- rabbitmqdata:/var/lib/rabbitmq
env_file: env/rabbitmq.env
mailcatcher:
image: sj26/mailcatcher
ports:
- "1080:1080"
## Selenium support, uncomment to enable
#selenium:
# image: selenium/standalone-chrome-debug:3.8.1
# ports:
# - "5900:5900"
# extra_hosts: *appextrahosts
volumes:
appdata:
dbdata:
rabbitmqdata:
sockdata:
ssldata:
Remember that you will need to connect to the running docker container. So you probably want to use TCP instead of Unix socket. Check the output of the docker ps command and look for running MySQL containers. If you find one then use MySQL command like this: MySQL -h 127.0.0.1 -P <mysql_port> (you will find a port in docker ps output). If you can't find any running MySQL container in docker ps output then try docker images to find MySQL image name and try something like this to run it: docker run -d -p 3306:3306 tutum/MySQL where "tutum/MySQL" is image name found in docker images.

Docker compose django, nginx, daphne expose internet in EC2

Hello i need expose the containers to internet i read thats is with ip table and works in in the instance but i can't access by internet for the moment and this is my configuration:
EC2 instance:
Ubuntu
Docker vserions:
Docker version 20.10.7, build f0df350
docker-compose version 1.25.0, build unknown
docker-compose.yml
version: '3.1'
services:
redis:
image: redis
command: redis-server --port 6379
ports:
- '6379:6379'
environment:
- REDIS_MODE="LRU"
- REDIS_MAXMEMORY="800mb"
server:
build: .
command: daphne rubrica.asgi:application --port 8000 --websocket_timeout -1 --bind 0.0.0.0 -v2
volumes:
- .:/src
- ${AWS_CREDENTIALS_PATH}:/root/.aws/
ports:
- "8000:8000"
links:
- redis
env_file:
- .env
nginx:
image: nginx
volumes:
- ./nginx/:/etc/nginx/
links:
- server
ports:
- "80:80"
- "443:443"
depends_on:
- server
command: ["nginx", "-g", "daemon off;"]
networks:
docker-network:
driver: networktest
network
sudo docker create --name networktest --network <instance ip> --publish 8080:80 --publish 443:443 nginx:latest
and this is the rules in my instance
If someone can help me to know what i need or a can't see in the configuration.

Port exposed with docker run but not docker-compose up

I am trying to run rabbitmq along with influxdb TICK stack with docker-compose. When I run rabbitmq with this command:docker run -d --rm -p 5672:5672 -p 15672:15672 rabbitmq:3-management, both ports are open and I am able to access from a remote machine. However, when I run rabbitmq as part of a docker-compose file, it is not accessable from a remote machine. Here is my docker-compose.yml file:
version: "3.7"
services:
influxdb:
image: influxdb
volumes:
- ./influxdb/influxdb/data/:/var/lib/influxdb/
- ./influxdb/influxdb/config/:/etc/influxdb/
ports:
- "8086:8086"
rabbitmq:
image: rabbitmq:3-management
volumes:
- ./rabbitmq/data:/var/lib/rabbitmq
ports:
- "15672:15672"
- "5672:5627"
telegraf:
image: telegraf
volumes:
- ./influxdb/telegraf/config/:/etc/telegraf/
- /proc:/host/proc:ro
depends_on:
- "influxdb"
- "rabbitmq"
chronograf:
image: chronograf
volumes:
- ./influxdb/chronograf/data/:/var/lib/chronograf/
ports:
- "8888:8888"
depends_on:
- "telegraf"
More information: when I run this with docker-compose up -d the 8086 and 8888 are accessible from a remote machine (I confirm with using nmap command). Also, either way I am able to access the rabbitmq management console at http://localhost:15672.
How can I set this up so I can access rabbitmq from a remote machine using docker-compose?
Thank you.
Looks like just a typo in the port mapping in docker-compose.yml: 5672:5627 should actually be 5672:5672.
Otherwise the docker-compose configuration looks just fine.

docker-compose cannot access to database port

dockerfile:
FROM anapsix/alpine-java:8_server-jre_unlimited
# copy application
COPY server.jar /opt/test/
COPY application.yml /opt/test/
# expose server ports
EXPOSE 8080 18080
# Run via dumb-init
WORKDIR /opt/test
ENTRYPOINT ["java"]
CMD ["-jar", "server.jar"]
docker-compose files:
services:
backend-server:
image: test.com/server:latest
build: .
depends_on:
- database-server
ports:
- "127.0.0.1:8080:8080"
- "127.0.0.1:18080:18080"
database-server:
image: postgres:9.6
ports:
- "127.0.0.1:5432:5432"
environment:
- POSTGRES_PASSWORD testtest
application property file:
spring:
datasource:
# use default user/database created by PostgreSQL Docker image upon startup
url: jdbc:postgresql://localhost/postgres
username: postgres
password: testtest
driver-class-name: org.postgresql.Driver
When I run the docker-compose up, it will create a database container and an application container which connects to the database container.
But the spring application container encounters some problem during bootup with error:
org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
docker container ls shows the database is running, and I can access it if I run the spring application directly.
a295bfd16e2c postgres:9.6 "docker-entrypoint.s…" About a minute ago Up About a minute 127.0.0.1:5432->5432/tcp server_database-server_1
So what would be the problem that I messed up?
Solution I found
services:
backend-server:
image: test.com/server:latest
build: .
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://database-server/postgres
depends_on:
- database-server
ports:
- 8080:8080
- 18080:18080
database-server:
image: postgres:9.6
ports:
- 5432:5432
environment:
- POSTGRES_PASSWORD testtest
But I still cannot access the application from localhost:8080 of my computer, even the log of the container says
2018-10-31 15:02:40.881 INFO 1 --- [ main]
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s):
8080 (http) with context path ''
2018-10-31 15:02:40.881 INFO 1 --- [ main]
com.test.server.Application : Started Application in
12.823 seconds (JVM running for 13.235)
I suggest to modify your docker-compose.yml file as given below and test it
services:
backend-server:
image: test.com/server:latest
build: .
depends_on:
- database-server
ports:
- 8080:8080
- 18080:18080
database-server:
image: postgres:9.6
ports:
- 5432:5432
environment:
- POSTGRES_PASSWORD testtest
services:
backend-server:
image: test.com/server:latest
build: .
depends_on:
- database-server
ports:
- "127.0.0.1:8080:8080" #change to 8080:8080 without ""and by default set to local so you dont need add local ip
- "127.0.0.1:18080:18080" #change to 18080:18080 without ""and by default set to local so you dont need add local ip
database-server:
image: postgres:9.6
ports:
- "127.0.0.1:5432:5432" #change to 5432:5432 without ""and by default set to local so you dont need add local ip
environment:
- POSTGRES_PASSWORD testtest

Docker exposing ports site can't be reached

I have exposed the required ports in my dockerfiles as well mapped them in my docker-compose.yml.
If i create containers without a docker-compose.yml i can access everything, but if i use docker-compose.yml file i cannot access 2 out of 3 images via a http-get request.
But according to docker port <container-name> the ports are mapped:
bitmovin#bitmovin-VirtualBox:~/Documents$ docker port php-container 8080:
0.0.0.0:8080
bitmovin#bitmovin-VirtualBox:~/Documents$ docker port php-container:
8080/tcp -> 0.0.0.0:8080
bitmovin#bitmovin-VirtualBox:~/Documents$ docker port comp-container:
8080/tcp -> 0.0.0.0:8070
bitmovin#bitmovin-VirtualBox:~/Documents$ docker port phpmyadmin-container:
8080/tcp -> 0.0.0.0:8090
I don't know why i cannot access the phpmyadmin-container and the php-container but the comp-container if i use a docker-compose file.
Did i miss something important?
php-image:
FROM php:7.0-apache
EXPOSE 8080
COPY Frontend/ /var/www/html/aw3somevideo/
COPY Frontend/ /var/www/html/
RUN chown -R www-data:www-data /var/www/html
RUN chmod -R 755 /var/www/html
RUN docker-php-ext-install mysqli
RUN php -i | grep -F .default_socket
comp-image:
FROM java:openjdk-8u91-jdk
EXPOSE 8070
CMD java -jar encoding-comparison-1.0.jar
ADD encoding-comparison-1.0.jar /encoding-comparison-1.0.jar
phpmyadmin-image:
FROM phpmyadmin/phpmyadmin
EXPOSE 8090
docker-compose.yml:
db:
image: mysql-image
ports:
- "3306:3306"
volumes:
- /var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=Bitmovin
- DB_NAME=aw3somevideo
- DB_USER=Bitmovin
- DB_PASS=Bitmovin
container_name: mysql-container
admin:
image: phpmyadmin-image
ports:
- "8090:8080"
links:
- db
container_name: phpmyadmin-container
backend:
image: comp-image
ports:
- "8070:8080"
volumes:
- ./src:/var/www/backend
links:
- db
container_name: comp-container
php:
image: php-image
volumes:
- ./src:/var/www/html
links:
- db
ports:
- "8080:8080"
container_name: php-container
The solution was to change the ports from admin and php from "8080:8080" and "8090:8080" to "8080:80" and "8090:80" respectively.

Resources