节点
server
和
redis
容器是在同一个容器中定义的
docker-compose.yml
:
version: '3.9'
services:
backend:
image: 127.0.0.1:5000/backend
container_name: backend
hostname: backend
restart: always
networks:
- wellerman
volumes:
- ./:/app/src
build: .
environment:
REDIS_HOST: 'localhost'
REDIS_PORT: 6379
ports:
- '3231:4000'
depends_on:
- redis
links:
- redis
redis:
container_name: redis
hostname: redis
restart: always
networks:
- wellerman
image: redis:latest
command: --port 6379
ports:
- '6379:6379'
networks:
wellerman:
external: true
网络的配置方式如下(快照是在后端节点
服务器
站了一会儿;
雷迪斯
,虽然工作正常,但未报告已连接到网络):
docker network inspect wellerman
[
{
"Name": "wellerman",
"Id": "xiqats19pc6gb6tvmre1thyhh",
"Created": "2021-08-26T15:56:49.678973091Z",
"Scope": "swarm",
"Driver": "overlay",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "10.0.15.0/24",
"Gateway": "10.0.15.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"dd114e62bb8dffe866e1293af30cb7ad86516dfaaae5eae04b9347507b26023c": {
"Name": "backend_backend.1.w1suc8ytt8jfxvs9syspx1uv6",
"EndpointID": "dd114e62bb8dffe866e1293af30cb7ad86516dfaaae5eae04b9347507b26023b",
"MacAddress": "02:42:0a:00:0f:25",
"IPv4Address": "10.0.15.37/24",
"IPv6Address": ""
},
"lb-wellerman": {
"Name": "wellerman-endpoint",
"EndpointID": "dd114e62bb8dffe866e1293af30cb7ad86516dfaaae5eae04b9347507b26023a",
"MacAddress": "02:42:0a:00:0f:26",
"IPv4Address": "10.0.15.38/24",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.driver.overlay.vxlanid_list": "4111"
},
"Labels": {},
"Peers": [
{
"Name": "ba2cce29a569",
"IP": "10.12.63.2"
}
]
}
]
节点
服务器
如果未与建立连接,则终止
雷迪斯
例如,由于这是一种持续的情况,它不断崩溃。
Redis
似乎按预期工作:
docker service inspect t7znrullne5x
[
{
"ID": "t7krullne5xvkze8xr3znlott",
"Version": {
"Index": 233743
},
"CreatedAt": "2021-08-26T15:55:05.529166159Z",
"UpdatedAt": "2021-08-26T15:55:05.534908594Z",
"Spec": {
"Name": "backend_redis",
"Labels": {
"com.docker.stack.image": "redis:latest",
"com.docker.stack.namespace": "backend"
},
"TaskTemplate": {
"ContainerSpec": {
"Image": "redis:latest@sha256:66ce9bc742609650afc3de7009658473ed601db4e926a5b16d239303383bacad",
"Labels": {
"com.docker.stack.namespace": "backend"
},
"Args": [
"--port",
"6379"
],
"Hostname": "redis",
"Privileges": {
"CredentialSpec": null,
"SELinuxContext": null
},
"StopGracePeriod": 10000000000,
"DNSConfig": {},
"Isolation": "default"
},
"Resources": {},
"RestartPolicy": {
"Condition": "any",
"Delay": 5000000000,
"MaxAttempts": 0
},
"Placement": {
"Platforms": [
{
"Architecture": "amd64",
"OS": "linux"
},
{
"OS": "linux"
},
{
"OS": "linux"
},
{
"Architecture": "arm64",
"OS": "linux"
},
{
"Architecture": "386",
"OS": "linux"
},
{
"Architecture": "mips64le",
"OS": "linux"
},
{
"Architecture": "ppc64le",
"OS": "linux"
},
{
"Architecture": "s390x",
"OS": "linux"
}
]
},
"Networks": [
{
"Target": "xiqats19pc6gb6tvmre1thyhh",
"Aliases": [
"redis"
]
}
],
"ForceUpdate": 0,
"Runtime": "container"
},
"Mode": {
"Replicated": {
"Replicas": 1
}
},
"UpdateConfig": {
"Parallelism": 1,
"FailureAction": "pause",
"Monitor": 5000000000,
"MaxFailureRatio": 0,
"Order": "stop-first"
},
"RollbackConfig": {
"Parallelism": 1,
"FailureAction": "pause",
"Monitor": 5000000000,
"MaxFailureRatio": 0,
"Order": "stop-first"
},
"EndpointSpec": {
"Mode": "vip",
"Ports": [
{
"Protocol": "tcp",
"TargetPort": 6379,
"PublishedPort": 6379,
"PublishMode": "ingress"
}
]
}
},
"Endpoint": {
"Spec": {
"Mode": "vip",
"Ports": [
{
"Protocol": "tcp",
"TargetPort": 6379,
"PublishedPort": 6379,
"PublishMode": "ingress"
}
]
},
"Ports": [
{
"Protocol": "tcp",
"TargetPort": 6379,
"PublishedPort": 6379,
"PublishMode": "ingress"
}
],
"VirtualIPs": [
{
"NetworkID": "iyu2r81xo9fjiyhxve36dcuxx",
"Addr": "10.0.0.143/24"
},
{
"NetworkID": "xiqats19pc6gb6tvmre1thyhh",
"Addr": "10.0.15.7/24"
}
]
}
}
]
从上面的信息来看
雷迪斯
与…有关
wellerman
网络(
network inspect
但没有显示出来)。
查看节点中的日志
服务器
我找到了关于
ECONNREFUSED (-111)
当试图到达
雷迪斯
例子
如果我更换
REDIS_HOST
环境。变量来自
localhost
到
雷迪斯
,我明白了
ENOTFOUND (-3008)
错误
还有,建立
127.0.0.1
或者主机的实际IP没有太大变化:这两个容器之间似乎不存在连接。
您建议检查或更改什么?