Нужно было всего лишь добавить "network_mode: host" в docker-compose. После того, как файл принял следующий вид, все заработало:
version: '3.8'
volumes:
pg_market:
services:
server:
image: 'server:latest'
build:
context: .
container_name: server
depends_on:
- pg_db
ports:
- "8080:8080"
network_mode: host
links:
- pg_db:database
recommendation:
image: 'recommendation:latest'
build:
context: .
container_name: recommendation
depends_on:
- pg_db
ports:
- "8082:8082"
network_mode: host
links:
- pg_db:database
pg_db:
image: postgres
environment:
- POSTGRES_PASSWORD=1
- POSTGRES_USER=postgres
- POSTGRES_DB=postgres
volumes:
- pg_market:/var/lib/postgresql/data
ports:
- "5432:5432"
network_mode: host
kafka:
image: wurstmeister/kafka
ports:
- "9092:9092"
network_mode: host
environment:
KAFKA_ADVERTISED_HOST_NAME: localhost
KAFKA_CREATE_TOPICS: recommendation
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181