i have project in which Rabbit is launched:
services:
rabbitmq:
image: rabbitmq:3-management-alpine
container_name: 'rabbitmq'
ports:
- 5672:5672
- 15672:15672
volumes:
- ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/
- ~/.docker-conf/rabbitmq/log/:/var/log/rabbitmq
networks:
- rabbitmq_go_net
networks:
rabbitmq_go_net:
driver: bridge
Then I made another project that connects to this queue. Without the doker, I just used localhost as the host and port number 5672.
I wanted to run another project in docker with a database:
version: '3'
services:
postgres:
image: postgres:12
restart: always
networks:
- rabbitmq_go_net
ports:
- '5432:5432'
volumes:
- ./db_data:/var/lib/postgresql/data
- ./app/internal/config/dbconfig/init.sql:/docker-entrypoint-initdb.d/create_tables.sql
env_file:
- ./app/internal/config/dbconfig/.env
healthcheck:
test: [ "CMD", "pg_isready", "-q", "-d", "devdb", "-U", "postgres" ]
timeout: 45s
interval: 10s
retries: 10
app:
build: app
networks:
- rabbitmq_go_net
depends_on:
postgres:
condition: service_healthy
volumes:
db_data:
networks:
rabbitmq_go_net:
driver: bridge
And now I can't connect to Rabbit.I tried to make a different network and with the same name, but every time I get the same error:
FATA[2022-07-31T13:24:09Z]ipstack/internal.(*app).startConsume() app.go:43 failed to connect to RabbitMQ due dial tcp 127.0.0.1:5672: connect: connection refused
Connect:
addr := fmt.Sprintf("amqp://%s:%s@%s:%s/", cfg.Username, cfg.Password, cfg.Host, cfg.Port)
Where host is the container name rabbitmq. Is it possible to do this, or is it necessary to put programs in a container in some other way?I will be glad to help