网络:
创建网络
[root@localhost ~]# podman network create mynetwork
/etc/cni/net.d/mynetwork.conflist
[root@localhost ~]# podman network ls
NAME VERSION PLUGINS
podman 0.4.0 bridge,portmap,firewall
mynetwork 0.4.0 bridge,portmap,firewall
修改新生成的网络配置文件的子网和网关或者创建时使用–subnet 指定网段和子网掩码,–gateway指定网关
[root@localhost ~]# vi /etc/cni/net.d/mynetwork.conflist
[root@localhost ~]# cat /etc/cni/net.d/mynetwork.conflist
{
"cniVersion": "0.4.0",
"name": "mynetwork",
"plugins": [
{
"type": "bridge",
"bridge": "cni-podman1",
"isGateway": true,
"ipMasq": true,
"ipam": {
"type": "host-local",
"routes": [
{
"dst": "0.0.0.0/0"
}
],
"ranges": [
[
{
"subnet": "192.168.85.0/24",
"gateway": "192.168.85.1"
}
]
]
}
},
{
"type": "portmap",
"capabilities": {
"portMappings": true
}
},
{
"type": "firewall",
"backend": ""
},
{
"type": "tuning"
}
]
}
修改/usr/share/containers/containers.conf文件设置默认网络为新创建的网络
[root@localhost ~]# cat /usr/share/containers/containers.conf
# The network name of the default CNI network to attach pods to.
#
default_network = "mynetwork" //添加此行
#default_network = "podman"
查看ip
[root@localhost ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/busybox latest ffe9d497c324 7 days ago 1.46 MB
[root@localhost ~]# podman run -d --name test ffe9d497c324
dc8af565994cbdd698b14ea6621db7e9fbcb11eb2cb652f530a4351df760af12
[root@localhost ~]# podman inspect test | grep -i ipaddr
"SecondaryIPAddresses": 192.168.100.2,
"IPAddress": "192.168.100.1",
删除网络
[root@localhost ~]# podman network ls
NAME VERSION PLUGINS
podman 0.4.0 bridge,portmap,firewall
mynetwork 0.4.0 bridge,portmap,firewall,tuning
[root@localhost ~]# podman network rm mynetwork
Deleted: mynetwork
[root@localhost ~]# podman network ls
NAME VERSION PLUGINS
podman 0.4.0 bridge,portmap,firewall
podman容器开机自启
root身份运行podman
//先创建一个容器
[root@localhost ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/busybox latest ffe9d497c324 7 days ago 1.46 MB
[root@localhost ~]# podman run -d --name test ffe9d497c324
9faff886f8f89736b170c4662a37a15f489dcf57a4a93a2ac8ffd2b3970ba2ee
[root@localhost ~]# podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9faff886f8f8 docker.io/library/busybox:latest sh 12 seconds ago Exited (0) 12 seconds ago test
///配置开机自启文件
[root@localhost ~]# vi /etc/systemd/system/test_conteainer.service
[root@localhost ~]# cat /etc/systemd/system/test_conteainer.service
[Unit]
Description=Podman Nginx Service
After=network.target
After=network-online.target
[Service]
Type=simple
ExecStart=/usr/bin/podman start -a test
ExecStop=/usr/bin/podman stop -t 10 test
Restart=always
[Install]
WantedBy=multi-user.target
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl enable --now test_conteainer.service
Created symlink from /etc/systemd/system/multi-user.target.wants/test_conteainer.service to /etc/systemd/system/test_conteainer.service.
//查看
[root@localhost ~]# systemctl status test_conteainer.service
● test_conteainer.service - Podman Nginx Service
Loaded: loaded (/etc/systemd/system/test_conteainer.service; enabled; vendor preset: disabled)
Active: active (running) since 三 2021-12-15 22:52:43 CST; 1min 4s ago
Process: 117687 ExecStop=/usr/bin/podman stop -t 10 test (code=exited, status=0/SUCCESS)
Process: 117566 ExecStart=/usr/bin/podman start -a test (code=exited, status=0/SUCCESS)
Main PID: 117566 (code=exited, status=0/SUCCESS)
|