-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docker blocking network of existing LXC containers #103
Comments
I ran into this yesterday and the problem seems to be how Docker messes with the FORWARD filter table in iptables:
These rules block all forwarded packets that aren't to, from, or between Docker containers. My LXC containers use a "br0" interface that's separate from the "docker0" bridge. |
@aaronp24, how did you get it working? |
I just manually flushed the FORWARD table and changed its default policy to ACCEPT
|
Oh wait, I forgot that I also found you could disable this behavior by putting this in
|
@aaronp24 Thank you! I can confirm that
works. After install of docker and prior to the setting Edit: I guess I spoke a little too soon. While this does restore lxc networking, it seems docker is not able to reach the internet now. I've deleted the
and have confirmed I now have networking in both docker and lxc. |
I think this fixed it for me:
|
fixed it for me. Should I be using
instead? |
|
Try using SNAT:
As long as you do not try to have publicly reachable services on docker, that should work to have a docker container reach the outside world. |
@gmcclins |
@elnull thank you. |
@elnull |
@andreheuer |
I set the environment variable
because I use static ip adresses for the host and the container. But still no success. The only commands that makes the container reachable are
So what am I doing wrong? |
Is there a solution? After every reboot, I have to set
again |
I've got a permanent solution using |
I have the same problem as @Cretection the link provided by @Psycho0verload does not help, because IPv4 Forwarding is already enabled. Is there a good overall solution for fixing issues with LXC container and Docker? |
I solved it with edit the |
At last I got one more: |
All solutions described here did not work in case when Although this output is the same for both cases (working & non-working):
I've observed that the order is important: When starting the LXC container first and then the docker containers, it works. Other way around not. My current workaround is to change |
Hmm, by the sounds of this issue not being acknowledged by the docker developers, it seems that using Docker alongside another container technology such as LXC is not really supported. It would be nice if they made a small update to how Docker handles the FORWARD table to allow for new/existing rules to still work as expected. Mind you, I do have Docker running on a Linux router/gateway machine in my home, and I have some services set in the FORWARD table, and those custom iptables entries are unaffected. I wonder if perhaps the issue is related to how LXC is managing it's bridge interface, and uses the FORWARD table in an non-conventional way. I've been wanting to play around with LXC, so I may take a deeper look into what exactly is going on here, and causing LXC to lose it's connection. If I do manage to figure anything out at all, I'll be sure to post it into this issue for others who might try running both container technologies in unison. I do not see any reason why both container technologies could not run together on the same host. I never ran into any issues on Debian 9 using a NAT behind a lxcbr0 bridge device. Here's what I did, I first stopped the docker daemon, cleared out everything docker placed into my iptables(shouldn't docker clear it's IP tables for me when it's stopped?), set the FORWARD to ACCEPT. Then, I proceeded to install lxc, lxcfs, and dnsmasq-base. bridge-utils was already installed. I configured lxc-net according to the documentation, and started that systemd service. This created my bridge interface, and added some rules into my iptables.
I then proceeded to create an lxc container, started it, and confirmed networking both into the container, and networking out to the world wide web was working as expected. Once that was all confirmed, I proceeded to start the docker daemon, where it then re-created it's own iptables rules. I then confirmed that both my docker and lxc containers had networking both inbound and outbound. Both container technologies appear to run on the same host together with no issues. I haven't tried a full host bridge network, where the LXC containers are fully exposed on the host's external network, but I am sure this will work even better as it shouldn't need to add any firewall rules, unless you need your LXC container to communicate back to your host over the network for some reason. |
I encountered the same issue, and was able to resolve it after reading the Docker documentation on how to setup Docker on a router. In short, you need to add your custom rules to the DOCKER-USER table -- it appears that Docker respects these rules (i.e. doesn't clobber them). For example, for my bridge interface br0, I added the following iptables rule:
|
Thank you @the-real-ed ! That is really helpful! How do you make this rule persistent? |
@mattelacchiato in Debian-based systems, you can install the The contents of the file should be something along the lines of:
|
Update Systemsudo apt update && sudo apt upgrade Install iptables-persistentsudo apt-get install iptables-persistent # Save current rules for v4 & v6 Add Docker on a router iptables rulesudo nano /etc/iptables/rules.v4 Bind lxc.network.link to br0sudo sed -i '/lxc.network.link/c\lxc.network.link = br0' /etc/piVCCU3/lxc.config |
I ran into some networking issues while using lxc-net and installing docker, as well. I'm not entirely sure what caused the networking issues, because after looking at the
Regardless, it may be a good idea to manually add lxc-net's Docker and iptables: Add iptables policies before Docker’s rules
|
I can confirm that after performing both steps suggested by @Cretection networking is restored for my LXC containers, and Docker networking remains unaffected after a reboot. |
I got struck by this hard. I've got a thread here that shows the situation and also how I got networking back for lxd. https://discuss.linuxcontainers.org/t/containers-fails-to-reach-internet/14671 |
The current solution to this problem in the LXD documentation doesn't work on Debian bookworm:
I had to make it bidirectional for networking to start working again, in my case:
To make it stick across reboots, it can be added to
|
FYI, we've updated the LXD documentation to have the returning traffic go through. This is checking the connection state rather than allowing all inbound traffic. |
I struggled a bit with this over the last few days, so here's some info on what finally worked for me. I am running Debian 11 on an Intel NUC with both Docker and LXD installed, and LXD containers configured with bridge networking so that they get regular LAN IP addresses via DHCP, and can communicate normally with the host. Entirely flushing FORWARD rules out of This logged tens of thousands of packets in just a few seconds. I grepped out relevant traffic using the container's
Incidentally, some cross-container broadcast and multicast traffic also happens and looks like this:
I explored adapting the style of rule suggested by @starkeepers by using the
This would have led to a lot of new rules to manage. I ended up settling on a single broader rule like @the-real-ed suggested above:
I also tried to make this rule persist across reboots using a
I had errors in syslog like the following, showing that the
To resolve this I added a new I created a script at
I created a
And enabled it as follows:
So far, this seems to be working reliably. |
@seanblanchfield thnx for your solution. What worked on my end what to adapt
And confirmed fixed permanently, it works after a reboot using Ubuntu 23.10. |
This bug blocks DHCP requests from LXC containers and Qemu/KVM VMs on a Debian 12 Bookworm machine. : - / This allows it through as others have shared: iptables -I DOCKER-USER -i vmbr0 -j ACCEPT |
For anyone who has #!/usr/bin/env bash
date > /var/log/post-docker-timestamp
iptables -N DOCKER-USER
iptables -I FORWARD -j DOCKER-USER
iptables -A DOCKER-USER -j RETURN
iptables -I DOCKER-USER -i br0 -j ACCEPT
iptables -I DOCKER-USER -o br0 -j ACCEPT Where Source: #810 (comment) |
Following the official documentation for LXD https://documentation.ubuntu.com/lxd/en/latest/howto/network_bridge_firewalld/#prevent-connectivity-issues-with-lxd-and-docker fixes the problem. I applied "Enable IPv4 forwarding" and "Allow egress network traffic flows". |
Looks like we missed the 7th birthday of this bug. Happy belated birthday, #103! |
FWIW, we've some refactoring of our iptables rules cooking in, and it should solve this issue (although that wasn't the main goal). Hopefully, it'll be released in v28.0 (ETA mid-November). |
I am running a server with LXC containers on it.
I found a software that was available as Docker containers, so I installed Docker on the server and tried that software.
Expected behavior
Both LXC containers should work normally, and new Docker containers should work.
If it isn't possible for Docker to start a container without interrupting existing containers due to any conceptual issue, I would expect Docker to detect that such a problem exists and to provide an overridable error message or at least a warning, that it might interfere with existing containers.
Actual behavior
The Docker containers work, but the LXC containers are suddenly disconnected from the network. The LXC containers are still running, and I can attach to them directly, but they aren't visible on the network anymore, they cannot be pinged, and their services aren't available anymore. Docker has disconnected the running LXC containers from the network.
Steps to reproduce the behavior
Install Debian Linux
Install LXC
Create a LXC container with it's own IP address
Run a server on the LXC container
Install Docker
Download and run a Docker container
Try to access the server in the LXC container over the network
Output of
docker version
:Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 4
Server Version: 17.07.0-ce
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 42
Dirperm1 Supported: true
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: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 3addd840653146c90a254301d6c3a663c7fd6429
runc version: 2d41c047c83e09a6d61d464906feb2a2f3c52aa4
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 4.9.0-3-amd64
Operating System: Debian GNU/Linux 9 (stretch)
OSType: linux
Architecture: x86_64
CPUs: 16
Total Memory: 31.41GiB
Name: servername
ID: ZQY3:PKBB:X7ZY:WY54:VKG4:IILY:42LG:KURS:4MXC:JR67:A6IX:T3KT
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Http Proxy: http://proxy:8080/
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No swap limit support
Additional environment details (AWS, VirtualBox, physical, etc.)
Linux version 4.9.0-3-amd64 (debian-kernel@lists.debian.org) (gcc version 6.3.0 20170516 (Debian 6.3.0-18) ) #1 SMP Debian 4.9.30-2+deb9u2 (2017-06-26)
The text was updated successfully, but these errors were encountered: