我有docker-compose
像这样
version: '3.7'
networks:
iam_network:
external:
name: foundation_iam
rdc_network:
name: rdcstu3_net
services:
rdcdeploy:
restart: "no"
container_name: rdcdeploy
build:
context: ./rdcdeploy
args:
- build_version
- build_type
image: rdcdeploy:$build_version
volumes:
- ./cfg:/cfg
networks:
- rdc_network
rdcrabbitmq:
restart: "no"
container_name: rdcrabbitmq
build:
context: ./rabbitmq
args:
- build_version
- build_type
image: rdcrabbitmq:$build_version
ports:
- "5772:5672"
- "15772:15672"
depends_on:
- rdcdeploy
volumes:
- ./cfg:/cfg
networks:
- rdc_network
rdcdb:
restart: "no"
container_name: rdcdb
build:
context: ./postgres
args:
- build_version
- build_type
image: rdcpostgres:$build_version
ports:
- "5532:5432"
depends_on:
- rdcdeploy
volumes:
- ./cfg:/cfg
networks:
- rdc_network
rdcdbdeploy:
restart: "no"
container_name: rdcdbdeploy
build:
context: ./rdcdbdeploy
args:
- build_version
- build_type
image: rdcdbdeploy:$build_version
depends_on:
- rdcdb
volumes:
- ./cfg:/cfg
networks:
- rdc_network
rihapp:
restart: "no"
container_name: rihapp
build:
context: ./rihserver
args:
- build_version
- build_type
image: rihapp:$build_version
ports:
- "9090:8080"
depends_on:
- rdcrabbitmq
- rdcdb
volumes:
- ./cfg:/cfg
networks:
- iam_network
- rdc_network
subscription_scheduler:
restart: "no"
container_name: subscription_scheduler
build:
context: ./subscription
args:
- build_version
- build_type
image: subscription_scheduler:$build_version
depends_on:
- rdcrabbitmq
- rdcdb
- rihapp
volumes:
- ./cfg:/cfg
networks:
- iam_network
- rdc_network
environment:
- rdc.subscription.instanceNumber=0
subscription_processor:
restart: "no"
container_name: subscription_processor
build:
context: ./subscription
args:
- build_version
- build_type
image: subscription_processor:$build_version
depends_on:
- rdcrabbitmq
- rdcdb
- rihapp
volumes:
- ./cfg:/cfg
networks:
- iam_network
- rdc_network
environment:
- rdc.subscription.instanceNumber=1
rdcsmoketest:
restart: "no"
container_name: rdcsmoketests
build:
context: ./rdcdeploy
image: rdcdeploy:$build_version
volumes:
- ./cfg:/cfg
depends_on:
- rihapp
networks:
- iam_network
- rdc_network
entrypoint:
- wait-for-rihapp.sh
- rdcdeploy
command: ["-x", "-z", "/cfg", "-c", "/cfg/config.yml", "docker"]
我使用docker-compose up
启动它,它表明容器已启动。
eedaa5e11a0e rdicdeploy:3.3.0.1 "wait-for-rihapp.sh…" 2 minutes ago Up 38 seconds rdicsmoketests
9178355cbca7 subscription_scheduler:3.3.0.1 "./wait-for-env.sh /…" 2 minutes ago Up 38 seconds subscription_scheduler
ae24a4b76f3e subscription_processor:3.3.0.1 "./wait-for-env.sh /…" 2 minutes ago Up 38 seconds subscription_processor
5f789ae74ef2 rihapp:3.3.0.1 "./wait_for_rdic_db.s…" 2 minutes ago Up 39 seconds 0.0.0.0:9090->8080/tcp rihapp
698b26d0ca37 rdicdbdeploy:3.3.0.1 "wait-for-env-db.sh …" 2 minutes ago Up 39 seconds rdicdbdeploy
592cb850f5b9 rdicrabbitmq:3.3.0.1 "wait-for-env.sh /cf…" 2 minutes ago Up 39 seconds 4369/tcp, 5671/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:5772->5672/tcp, 0.0.0.0:15772->15672/tcp rdicrabbitmq
505a0f36528f rdicpostgres:3.3.0.1 "wait-for-env.sh /cf…" 2 minutes ago Up 39 seconds 0.0.0.0:5532->5432/tcp
但是由于某些原因,没有容器能够连接Rabbitmq或postgres。
rabbitmq
的日志表明它们已经启动
2020-07-24 10:32:13.226 [info] <0.370.0> Running boot step direct_client defined by app rabbit
2020-07-24 10:32:13.226 [info] <0.370.0> Running boot step os_signal_handler defined by app rabbit
2020-07-24 10:32:13.226 [info] <0.489.0> Swapping OS signal event handler (erl_signal_server) for our own
2020-07-24 10:32:13.262 [info] <0.539.0> Management plugin: HTTP (non-TLS) listener started on port 15672
2020-07-24 10:32:13.262 [info] <0.645.0> Statistics database started.
2020-07-24 10:32:13.262 [info] <0.644.0> Starting worker pool 'management_worker_pool' with 3 processes in it
2020-07-24 10:32:13.480 [info] <0.8.0> Server startup complete; 3 plugins started.
* rabbitmq_management
* rabbitmq_web_dispatch
* rabbitmq_management_agent
completed with 3 plugins.
也postgres
server started
CREATE DATABASE
CREATE ROLE
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
waiting for server to shut down...LOG: received fast shutdown request
.LOG: aborting any active transactions
LOG: autovacuum launcher shutting down
LOG: shutting down
LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
LOG: database system was shut down at 2020-07-24 10:30:59 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
Environment Available - proceeding with startup docker-entrypoint.sh postgres
LOG: database system was interrupted; last known up at 2020-07-24 10:31:00 UTC
LOG: database system was not properly shut down; automatic recovery in progress
LOG: invalid record length at 0/14EEEA0: wanted 24, got 0
LOG: redo is not required
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
但是应用程序尝试连接5772
,但是对于Rabbitmq和postgres
,连接被拒绝了
psql: error: could not connect to server: could not connect to server: Connection refused
rihapp | Is the server running on host "localhost" (127.0.0.1) and accepting
rihapp | TCP/IP connections on port 5532?
它还会生成.env
个文件,其中包含APPS之类的环境变量
DATABASE_URL=postgres://rdc:rdc@localhost:5532/pg_db
spring.datasource.url=jdbc:postgresql://localhost:5532/pg_db
spring.rabbitmq.host=localhost
spring.rabbitmq.port=5772
可能是什么问题?感觉就像是某种网络问题。
答案 0 :(得分:2)
似乎您已配置客户端以与localhost:X
上的服务器联系,我是否正确?
在这种情况下,您需要知道docker-compose中的容器具有不同的网络cgroup,并且能够通过网桥接口相互访问。这意味着在容器中,您应该使用rdcrabbitmq:5672
而不是localhost:5772