【问题标题】:Docker-compose Error : cannot restrict inter-container communicationDocker-compose 错误:无法限制容器间通信
【发布时间】:2018-08-20 12:07:14
【问题描述】:

我尝试使用docker stack deploy 命令运行我的应用程序服务。使用此命令,我收到以下错误:

"starting container failed: error creating external connectivity network: cannot restrict inter-container communication: please ensure that br_netfilter kernel module is loaded"

我的服务的 Docker-compose 文件如下,它只包含一个服务:

version: '3.1'

services:
  app_service:
    image: app-image:latest

但如果我尝试使用简单的docker run app-image:latest 运行此服务,那么它可以正常运行。这可能是什么问题?

以下是docker info的输出:

Containers: 44
 Running: 0
 Paused: 0
 Stopped: 44
Images: 11
Server Version: 18.06.0-ce
Storage Driver: vfs
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: active
 NodeID: ifx6qbtt8ylkxqxgjbk67rc6e
 Is Manager: true
 ClusterID: p8s73udo6dq4ivm95frfrfb4f
 Managers: 1
 Nodes: 1
 Orchestration:
  Task History Retention Limit: 5
 Raft:
  Snapshot Interval: 10000
  Number of Old Snapshots to Retain: 0
  Heartbeat Tick: 1
  Election Tick: 10
 Dispatcher:
  Heartbeat Period: 5 seconds
 CA Configuration:
  Expiry Duration: 3 months
  Force Rotate: 0
 Autolock Managers: false
 Root Rotation In Progress: false
 Node Address: 10.10.140.7
 Manager Addresses:
  10.10.140.7:2377
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: d64c661f1d51c48782c9cec8fda7604785f93587
runc version: 69663f0bd4b60df09991c08812a60108003fa340
init version: fec3683
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.4.0-131-generic
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 8GiB
Name: RNI-PD-CT06
ID: UEG4:OVFJ:G55V:KIR4:QJD2:LQUJ:DVLQ:WKJY:AKQB:MKSO:Z4ZN:UF56
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 38
 Goroutines: 161
 System Time: 2018-08-20T12:25:06.808731767Z
 EventsListeners: 0
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

WARNING: No swap limit support
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

【问题讨论】:

  • 尝试重新安装docker
  • 什么是版本 (docker info) ?还有docker inspect networks ?
  • @AndriyIvaneyko 我在我的帖子中添加了docker infodocker inspect networks 命令输出
  • 请使用:docker network inspect
  • lxc config show manager --expanded 的内容是什么?

标签: docker docker-compose dockerfile docker-swarm


【解决方案1】:

根据警告消息,bridge-nf-call-iptables 已禁用,请运行以下代码来解决该警告:

sudo sysctl net.bridge.bridge-nf-call-iptables=1
sudo sysctl net.bridge.bridge-nf-call-ip6tables=1

另外,确保br_netfilter 模块已启用,执行下面的运行命令并确保br_netfilter 列在linux.kernel_modules 中:

 lxc profile show docker

如果未列出,请复制linux.kernel_modules 中列出的所有值并将,br_netfilter 添加到复制值的末尾,而不是将所有值放在下面的命令中而不是:

lxc profile set docker linux.kernel_modules <[COPIED_LIST]>

【讨论】:

  • 我在运行 sudo sysctl net.bridge.bridge-nf-call-iptables=1 时收到 sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-iptables: No such file or directory,这是否意味着我的 CentOS 设置有问题?
  • @rishi007bansod 没必要,其他命令呢?你有远程节点吗?
  • 我们没有任何远程节点。目前只有在 swarm 中的节点上。 lxc 命令在我的系统中不存在,我会安装它并让你知道它的输出。
  • @rishi007bansod 我想启用 bridge-nf-call-iptables 很重要
  • 另外,我们在主机 VM 中使用 linux 容器。在这个 linux 容器中,我们设置了 docker。如何在linux容器中设置参数sudo sysctl net.bridge.bridge-nf-call-iptables=1
【解决方案2】:

需要添加network,以便docker之间互通

You will need to add this tag -> network: dockerNetwork

然后

services:
  app_service:
    image: app-image:latest
  network: dockerNetwork

  app_service2:
    image: app-image2:latest
  network: dockerNetwork

network: dockerNetwork

【讨论】:

  • 添加此网络字段后,仍然报同样的错误
猜你喜欢
  • 2019-03-07
  • 2018-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-10
相关资源
最近更新 更多