Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.

Chapter 8. Managing a container network


The chapter provides information about how to communicate among containers.

8.1. Listing container networks

In Podman, there are two network behaviors - rootless and rootful:

  • Rootless networking - the network is setup automatically, the container does not have an IP address.
  • Rootful networking - the container has an IP address.

Prerequisites

  • The container-tools meta-package is installed.

Procedure

  • List all networks as a root user:

    # podman network ls
    NETWORK ID    NAME        VERSION     PLUGINS
    2f259bab93aa  podman      0.4.0       bridge,portmap,firewall,tuning
    Copy to Clipboard Toggle word wrap
    • By default, Podman provides a bridged network.
    • List of networks for a rootless user is the same as for a rootful user.

8.2. Inspecting a network

Display the IP range, enabled plugins, type of network, and so on, for a specified network listed by the podman network ls command.

Prerequisites

  • The container-tools meta-package is installed.

Procedure

  • Inspect the default podman network:

    $ podman network inspect podman
    [
        {
            "cniVersion": "0.4.0",
            "name": "podman",
            "plugins": [
                {
                    "bridge": "cni-podman0",
                    "hairpinMode": true,
                    "ipMasq": true,
                    "ipam": {
                        "ranges": [
                            [
                                {
                                    "gateway": "10.88.0.1",
                                    "subnet": "10.88.0.0/16"
                                }
                            ]
                        ],
                        "routes": [
                            {
                                "dst": "0.0.0.0/0"
                            }
                        ],
                        "type": "host-local"
                    },
                    "isGateway": true,
                    "type": "bridge"
                },
                {
                    "capabilities": {
                        "portMappings": true
                    },
                    "type": "portmap"
                },
                {
                    "type": "firewall"
                },
                {
                    "type": "tuning"
                }
            ]
        }
    ]
    Copy to Clipboard Toggle word wrap

    You can see the IP range, enabled plugins, type of network, and other network settings.

8.3. Creating a network

Use the podman network create command to create a new network.

Note

By default, Podman creates an external network. You can create an internal network using the podman network create --internal command. Containers in an internal network can communicate with other containers on the host, but cannot connect to the network outside of the host nor be reached from it.

Prerequisites

  • The container-tools meta-package is installed.

Procedure

  • Create the external network named mynet:

    # podman network create mynet
    /etc/cni/net.d/mynet.conflist
    Copy to Clipboard Toggle word wrap

Verification

  • List all networks:

    # podman network ls
    NETWORK ID    NAME        VERSION     PLUGINS
    2f259bab93aa  podman      0.4.0       bridge,portmap,firewall,tuning
    11c844f95e28  mynet       0.4.0       bridge,portmap,firewall,tuning,dnsname
    Copy to Clipboard Toggle word wrap

    You can see the created mynet network and default podman network.

Note

Beginning with Podman 4.0, the DNS plugin is enabled by default if you create a new external network by using the podman network create command.

8.4. Connecting a container to a network

Use the podman network connect command to connect the container to the network.

Prerequisites

  • The container-tools meta-package is installed.
  • A network has been created by using the podman network create command.
  • A container has been created.

Procedure

  • Connect a container named mycontainer to a network named mynet:

    # podman network connect mynet mycontainer
    Copy to Clipboard Toggle word wrap

Verification

  • Verify that the mycontainer is connected to the mynet network:

    # podman inspect --format='{{.NetworkSettings.Networks}}' mycontainer
    map[podman:0xc00042ab40 mynet:0xc00042ac60]
    Copy to Clipboard Toggle word wrap

    You can see that mycontainer is connected to mynet and podman networks.

8.5. Disconnecting a container from a network

Use the podman network disconnect command to disconnect the container from the network.

Prerequisites

  • The container-tools meta-package is installed.
  • A network has been created by using the podman network create command.
  • A container is connected to a network.

Procedure

  • Disconnect the container named mycontainer from the network named mynet:

    # podman network disconnect mynet mycontainer
    Copy to Clipboard Toggle word wrap

Verification

  • Verify that the mycontainer is disconnected from the mynet network:

    # podman inspect --format='{{.NetworkSettings.Networks}}' mycontainer
    map[podman:0xc000537440]
    Copy to Clipboard Toggle word wrap

    You can see that mycontainer is disconnected from the mynet network, mycontainer is only connected to the default podman network.

8.6. Removing a network

Use the podman network rm command to remove a specified network.

Prerequisites

  • The container-tools meta-package is installed.

Procedure

  1. List all networks:

    # podman network ls
    NETWORK ID    NAME        VERSION     PLUGINS
    2f259bab93aa  podman      0.4.0       bridge,portmap,firewall,tuning
    11c844f95e28  mynet       0.4.0       bridge,portmap,firewall,tuning,dnsname
    Copy to Clipboard Toggle word wrap
  2. Remove the mynet network:

    # podman network rm mynet
    mynet
    Copy to Clipboard Toggle word wrap
Note

If the removed network has associated containers with it, you have to use the podman network rm -f command to delete containers and pods.

Verification

  • Check if mynet network was removed:

    # podman network ls
    NETWORK ID    NAME        VERSION     PLUGINS
    2f259bab93aa  podman      0.4.0       bridge,portmap,firewall,tuning
    Copy to Clipboard Toggle word wrap

8.7. Removing all unused networks

Use the podman network prune to remove all unused networks. An unused network is a network which has no containers connected to it. The podman network prune command does not remove the default podman network.

Prerequisites

  • The container-tools meta-package is installed.

Procedure

  • Remove all unused networks:

    # podman network prune
    WARNING! This will remove all networks not used by at least one container.
    Are you sure you want to continue? [y/N] y
    Copy to Clipboard Toggle word wrap

Verification

  • Verify that all networks were removed:

    # podman network ls
    NETWORK ID    NAME        VERSION     PLUGINS
    2f259bab93aa  podman      0.4.0       bridge,portmap,firewall,tuning
    Copy to Clipboard Toggle word wrap
Nach oben
Red Hat logoGithubredditYoutubeTwitter

Lernen

Testen, kaufen und verkaufen

Communitys

Über Red Hat Dokumentation

Wir helfen Red Hat Benutzern, mit unseren Produkten und Diensten innovativ zu sein und ihre Ziele zu erreichen – mit Inhalten, denen sie vertrauen können. Entdecken Sie unsere neuesten Updates.

Mehr Inklusion in Open Source

Red Hat hat sich verpflichtet, problematische Sprache in unserem Code, unserer Dokumentation und unseren Web-Eigenschaften zu ersetzen. Weitere Einzelheiten finden Sie in Red Hat Blog.

Über Red Hat

Wir liefern gehärtete Lösungen, die es Unternehmen leichter machen, plattform- und umgebungsübergreifend zu arbeiten, vom zentralen Rechenzentrum bis zum Netzwerkrand.

Theme

© 2025 Red Hat