Docker does not create bridge network by default

I have two laptops both with xubuntu, one has version 20.04 and the other has version 22.04.

20.04: when I create a dockerfile and add commands to download packages, they download without problem “sudo apt-get update”.

22.04: when I create a dockerfile and add commands to download packages, it is impossible to download the packages using “sudo apt-get update”, also none of the containers created in docker using xubuntu 22.04, none of the containers have internet connection.

I have identified that docker in version 20.04 creates by default the bridge network but in version 22.04 it does not create it.

does anyone know how can i add the default bridge network that docker creates?

I was recreating a network similar to how it looks in the inspection of the bridge network but I can’t get it right.

note xubuntu 22.04 docker does not create the bridge network but in 20.04 it does.

You can create a bridge network manually. This can be done by running the following command in the terminal:

docker network create -d bridge my_bridge_network

You can then start a container using this network by specifying the --network option and providing the name of the bridge network, like so:

docker run -it --network my_bridge_network my_image

You can inspect the network using the following command to verify that the network was created correctly:

docker network inspect my_bridge_network
1 Like

The suggestion of @ajeetraina is to create a user defined network. Compared to the default bridge network, they provide dns-based service discovery, and allows container to container communication using container names.

In order to use a user default network during builds, you need to add the --network my_bridge_network argument to docker built as well.

Thus said, I am curious about why the default bridge is not available.
Please share the outputs of these commands:

  • ip address show docker0
  • docker network inspect default
  • docker info
2 Likes

Thank you for answering, these are the results returned by the terminal

Xubuntu 22.04:

eaaldark@eaaldark-HP-Laptop-14-cf2xxx:~$ ip address show docker0

Device "docker0" does not exist.
eaaldark@eaaldark-HP-Laptop-14-cf2xxx:~$ docker network inspect default

[]
Error: No such network: default
eaaldark@eaaldark-HP-Laptop-14-cf2xxx:~$ docker info

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.10.0-docker)
  compose: Docker Compose (Docker Inc., v2.15.1)
  scan: Docker Scan (Docker Inc., v0.23.0)

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 14
 Server Version: 20.10.23
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 31aa4358a36870b21a992d3ad2bef29e1d693bec
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.15.0-58-generic
 Operating System: Ubuntu 22.04.1 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 7.591GiB
 Name: eaaldark-HP-Laptop-14-cf2xxx
 ID: UFQ6:FUMH:EPZW:DMA7:DTV4:7YQF:7ZXW:TZKB:CO6A:4T75:PNI3:TD37
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Xubuntu 20.04:

eaaldark@eaaldark-Aspire-ES1-411:~$ ip address show docker0

6: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:f7:7d:5d:e9 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
eaaldark@eaaldark-Aspire-ES1-411:~$ docker network inspect default

[]
Error: No such network: default
eaaldark@eaaldark-Aspire-ES1-411:~$ docker info

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.8.2)
  compose: Docker Compose (Docker Inc., v2.5.0)

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 69
 Server Version: 20.10.17
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc version: 
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.15.0-58-generic
 Operating System: Ubuntu Core 18
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 7.648GiB
 Name: eaaldark-Aspire-ES1-411
 ID: C7XH:WEGY:XC4E:EULY:5SCC:FJAX:ZPZK:VQUM:FYGV:C5U5:FF6R:Z2DS
 Docker Root Dir: /var/snap/docker/common/var-lib-docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

It seems to work, I have no problem, but I always have to specify it for each project in the compose file or when creating dockerfile. I will continue to investigate more about my problem.

Thanks, for me it is a temporary solution, but functional.

I have never seen on any Ubuntu version that the docker0 interface and the default bridge network were not created. If either one of them doesn’t exist, a restart of the docker service (or a reboot) should create them. Strange that this is not happening for you.

My bad, this should have been docker network inspect bridge

I researched it a little and I encountered these:

  • caused by possible side effects from existing configuration in /etc/docker/daemon.json.
  • caused by a network range collision between the local lan and docker’s docker0 range 172.17.0.0/16.
  • suggestion to remove the docker network configuration after(!) stopping the docker service: rm -rf /var/lib/docker/network (warning: as a result all container networks will be gone!)
1 Like

Hi, I also tried “docker network inspect bridge” and it returned the same result, but there is a detail, I uninstalled docker and reinstalled it through snap packages and the network bridge was created, but after installing docker through snap I try to create a container and there is still no internet connection.

I will try what you say, if not, I will have to try something I was also reading about resolv.conf on my laptop, for me this is new and I am a bit disoriented.

I’ve tried adding more addresses to the container in the resolv.conf file According to what I’ve read, but it still doesn’t work.

The snap package is not a vanilla distribution, it is modified to align with the philosophy of snap. It’s maintained and supported by Canonical. We don’t support it here. Many people managed to get a double installation: one from either a distro package or from docker’s repos + the snap package.

I would highly suggest removing the snap package and install docker-ce (not Docker Desktop) from docker’s repository, following these instructions: Install Docker Engine on Ubuntu | Docker Documentation.

Note: the whole state of the snap installation will not be available for the docker-ce installation, as both use different folders.

Thanks, I installed the package you provided from the link and it did not create the bridged network, but as you mentioned about deleting the docker network folder, I first shut down the docker service then deleted the folder and restarted the service, now in the terminal the bridged network shows data when inspecting it.

eaaldark@eaaldark-HP-Laptop-14-cf2xxx:~$ docker network inspect bridge
[
    {
        "Name": "bridge",
        "Id": "a7e4481edd44248df80a9244342c7e1a55e0331aba2e7cf0479141b4ad4a8ed6",
        "Created": "2023-02-02T21:30:59.549770295-05:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]

So at the end it was an inconsistency/corruption of the docker network configuration.
The output of network inspect looks good to me.

Removing the existing configuration file (/etc/docker/daemon.json) solved my issue. After restarting the docker service, docker0 network interface was created automatically again. Thank you @meyay !!

1 Like