Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 9. Managing a container network
The chapter provides information about how to communicate among containers.
9.1. Listing container networks Copier lienLien copié sur presse-papiers!
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-toolsmeta-package is installed.
Procedure
List all networks as a root user:
podman network ls
# podman network ls NETWORK ID NAME VERSION PLUGINS 2f259bab93aa podman 0.4.0 bridge,portmap,firewall,tuningCopy to Clipboard Copied! Toggle word wrap Toggle overflow - By default, Podman provides a bridged network.
- List of networks for a rootless user is the same as for a rootful user.
9.2. Inspecting a network Copier lienLien copié sur presse-papiers!
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-toolsmeta-package is installed.
Procedure
Inspect the default
podmannetwork:Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can see the IP range, enabled plugins, type of network, and other network settings.
9.3. Creating a network Copier lienLien copié sur presse-papiers!
Use the podman network create command to create a new network.
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-toolsmeta-package is installed.
Procedure
Create the external network named
mynet:podman network create mynet
# podman network create mynet /etc/cni/net.d/mynet.conflistCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
List all networks:
podman network ls
# 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,dnsnameCopy to Clipboard Copied! Toggle word wrap Toggle overflow You can see the created
mynetnetwork and defaultpodmannetwork.
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.
9.4. Connecting a container to a network Copier lienLien copié sur presse-papiers!
Use the podman network connect command to connect the container to the network.
Prerequisites
-
The
container-toolsmeta-package is installed. -
A network has been created by using the
podman network createcommand. - A container has been created.
Procedure
Connect a container named
mycontainerto a network namedmynet:podman network connect mynet mycontainer
# podman network connect mynet mycontainerCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify that the
mycontaineris connected to themynetnetwork:podman inspect --format='{{.NetworkSettings.Networks}}' mycontainer# podman inspect --format='{{.NetworkSettings.Networks}}' mycontainer map[podman:0xc00042ab40 mynet:0xc00042ac60]Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can see that
mycontaineris connected tomynetandpodmannetworks.
9.5. Disconnecting a container from a network Copier lienLien copié sur presse-papiers!
Use the podman network disconnect command to disconnect the container from the network.
Prerequisites
-
The
container-toolsmeta-package is installed. -
A network has been created by using the
podman network createcommand. - A container is connected to a network.
Procedure
Disconnect the container named
mycontainerfrom the network namedmynet:podman network disconnect mynet mycontainer
# podman network disconnect mynet mycontainerCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify that the
mycontaineris disconnected from themynetnetwork:podman inspect --format='{{.NetworkSettings.Networks}}' mycontainer# podman inspect --format='{{.NetworkSettings.Networks}}' mycontainer map[podman:0xc000537440]Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can see that
mycontaineris disconnected from themynetnetwork,mycontaineris only connected to the defaultpodmannetwork.
9.6. Removing a network Copier lienLien copié sur presse-papiers!
Use the podman network rm command to remove a specified network.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
List all networks:
podman network ls
# 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,dnsnameCopy to Clipboard Copied! Toggle word wrap Toggle overflow Remove the
mynetnetwork:podman network rm mynet
# podman network rm mynet mynetCopy to Clipboard Copied! Toggle word wrap Toggle overflow
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
mynetnetwork was removed:podman network ls
# podman network ls NETWORK ID NAME VERSION PLUGINS 2f259bab93aa podman 0.4.0 bridge,portmap,firewall,tuningCopy to Clipboard Copied! Toggle word wrap Toggle overflow
9.7. Removing all unused networks Copier lienLien copié sur presse-papiers!
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-toolsmeta-package is installed.
Procedure
Remove all unused networks:
podman network prune
# 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] yCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify that all networks were removed:
podman network ls
# podman network ls NETWORK ID NAME VERSION PLUGINS 2f259bab93aa podman 0.4.0 bridge,portmap,firewall,tuningCopy to Clipboard Copied! Toggle word wrap Toggle overflow