知乎专栏 |
目录
某些 Redhat 家族的 Linux 是自带 Podman,例如 Almalinux 9.0,RockyLinux没有自带 podman 需要自己安装,是方法执行下面的命令
[root@netkiller ~]# dnf install -y podman
初始化,启动 Podman
podman machine init podman machine start
操作演示
neo@MacBook-Pro-M2 ~ % podman machine init Downloading VM image: fedora-coreos-37.20221127.2.0-qemu.aarch64.qcow2.xz: done Extracting compressed file Image resized. Machine init complete To start your machine run: podman machine start neo@MacBook-Pro-M2 ~ % podman machine start Starting machine "podman-machine-default" Waiting for VM ... Mounting volume... /Users/neo:/Users/neo This machine is currently configured in rootless mode. If your containers require root permissions (e.g. ports < 1024), or if you run into compatibility issues with non-podman clients, you can switch using the following command: podman machine set --rootful API forwarding listening on: /Users/neo/.local/share/containers/podman/machine/podman-machine-default/podman.sock The system helper service is not installed; the default Docker API socket address can't be used by podman. If you would like to install it run the following commands: sudo /opt/homebrew/Cellar/podman/4.3.1/bin/podman-mac-helper install podman machine stop; podman machine start You can still connect Docker API clients by setting DOCKER_HOST using the following command in your terminal session: export DOCKER_HOST='unix:///Users/neo/.local/share/containers/podman/machine/podman-machine-default/podman.sock' Machine "podman-machine-default" started successfully
安装 python 3.13
[root@netkiller ~]# dnf install python3.13 python3.13-pip [root@netkiller ~]# rm -f /usr/bin/python3 [root@netkiller ~]# ln -s /usr/bin/python3.13 /usr/bin/python3
[root@netkiller ~]# dnf install -y podman-compose [root@netkiller ~]# pip install podman-compose
验证是否正常工作
[root@netkiller ~]# podman compose Run compose workloads via an external provider such as docker-compose or podman-compose Description: This command is a thin wrapper around an external compose provider such as docker-compose or podman-compose. This means that podman compose is executing another tool that implements the compose functionality but sets up the environment in a way to let the compose provider communicate transparently with the local Podman socket. The specified options as well the command and argument are passed directly to the compose provider. The default compose providers are docker-compose and podman-compose. If installed, docker-compose takes precedence since it is the original implementation of the Compose specification and is widely used on the supported platforms (i.e., Linux, Mac OS, Windows). If you want to change the default behavior or have a custom installation path for your provider of choice, please change the compose_providers field in containers.conf(5) to compose_providers = ["/path/to/provider"]. You may also set the PODMAN_COMPOSE_PROVIDER environment variable. Usage: podman compose [options] Examples: podman compose -f nginx.yaml up --detach podman --log-level=debug compose -f many-images.yaml pull >>>> Executing external compose provider "/usr/local/bin/podman-compose". Please see podman-compose(1) for how to disable this message. <<<< usage: podman-compose [-h] [-v] [--in-pod in_pod] [--pod-args pod_args] [--env-file env_file] [-f file] [--profile profile] [-p PROJECT_NAME] [--podman-path PODMAN_PATH] [--podman-args args] [--podman-pull-args args] [--podman-push-args args] [--podman-build-args args] [--podman-inspect-args args] [--podman-run-args args] [--podman-start-args args] [--podman-stop-args args] [--podman-rm-args args] [--podman-volume-args args] [--no-ansi] [--no-cleanup] [--dry-run] [--parallel PARALLEL] [--verbose] {help,version,wait,systemd,pull,push,build,up,down,ps,run,exec,start,stop,restart,logs,config,port,pause,unpause,kill,stats,images} ... options: -h, --help show this help message and exit -v, --version show version --in-pod in_pod Specify pod usage: 'true' - create/use a pod named pod_<project name> 'false' - do not use a pod '<name>' - create/use a custom pod with the given name --pod-args pod_args custom arguments to be passed to `podman pod` --env-file env_file Specify an alternate environment file -f, --file file Specify an compose file (default: docker-compose.yml) or '-' to read from stdin. --profile profile Specify a profile to enable -p, --project-name PROJECT_NAME Specify an alternate project name (default: directory name) --podman-path PODMAN_PATH Specify an alternate path to podman (default: use location in $PATH variable) --podman-args args custom global arguments to be passed to `podman` --podman-pull-args args custom arguments to be passed to `podman pull` --podman-push-args args custom arguments to be passed to `podman push` --podman-build-args args custom arguments to be passed to `podman build` --podman-inspect-args args custom arguments to be passed to `podman inspect` --podman-run-args args custom arguments to be passed to `podman run` --podman-start-args args custom arguments to be passed to `podman start` --podman-stop-args args custom arguments to be passed to `podman stop` --podman-rm-args args custom arguments to be passed to `podman rm` --podman-volume-args args custom arguments to be passed to `podman volume` --no-ansi Do not print ANSI control characters --no-cleanup Do not stop and remove existing pod & containers --dry-run No action; perform a simulation of commands --parallel PARALLEL --verbose Print debugging output command: {help,version,wait,systemd,pull,push,build,up,down,ps,run,exec,start,stop,restart,logs,config,port,pause,unpause,kill,stats,images} help show help version show version wait wait running containers to stop systemd create systemd unit file and register its compose stacks pull pull stack images push push stack images build build stack images up Create and start the entire stack or some of its services down tear down entire stack ps show status of containers run create a container similar to a service to run a one-off command exec execute a command in a running container start start specific services stop stop specific services restart restart specific services logs show logs from services config displays the compose file port Prints the public port for a port binding. pause Pause all running containers unpause Unpause all running containers kill Kill one or more running containers with a specific signal stats Display percentage of CPU, memory, network I/O, block I/O and PIDs for services. images List images used by the created containers
启用 socket
systemctl enable podman.socket systemctl start podman.socket systemctl status podman.socket
验证 sock 是否正常工作
[root@localhost ~]# curl -H "Content-Type: application/json" --unix-socket /run/podman/podman.sock http://localhost/_ping OK
此时可以使用 docker compose
[root@localhost ~]# ln -s /run/podman/podman.sock /var/run/docker.sock