如何从 Windows 命令行执行 podman-compose?

问题描述 投票:0回答:3

我已将“Docker Desktop for Windows”替换为 Podman 和 Podman Desktop。我还安装了 podman-compose。 podman 和 podman-compose 在 WSL 命令行上运行良好(我安装了 Ubuntu 发行版)。 我还可以在 Windows 命令行(cmd 和 PowerShell 中)上执行“podman”。但是,“podman-compose”不被识别为命令。

还需要什么才能在 Windows 命令行上执行“podman-compose”?我用 google 搜索了一下,但我发现的所有指令似乎都假设在 WSL 的 shell 中执行该指令。

这可能吗?我可以想象,在 WSL 中将当前的 Windows 路径传递给 shell 和其他细节可能会有点问题......

补充-回复@mre(如下):

感谢您的指导。我处决了他们。前三行运行正常,但最后一行产生:

(venv-podman) C:\Users\mmo>podman-compose --version
podman-compose version: 1.0.6
['podman', '--version', '']
Traceback (most recent call last):
  File "C:\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\mmo\venv-podman\Scripts\podman-compose.exe\__main__.py", line 7, in <module>
  File "C:\Users\mmo\venv-podman\lib\site-packages\podman_compose.py", line 2941, in main
    podman_compose.run()
  File "C:\Users\mmo\venv-podman\lib\site-packages\podman_compose.py", line 1406, in run
    self.podman.output(["--version"], "", []).decode("utf-8").strip()
  File "C:\Users\mmo\venv-podman\lib\site-packages\podman_compose.py", line 1098, in output
    return subprocess.check_output(cmd_ls)
  File "C:\Python310\lib\subprocess.py", line 420, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "C:\Python310\lib\subprocess.py", line 501, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Python310\lib\subprocess.py", line 969, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Python310\lib\subprocess.py", line 1438, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

(venv-podman) C:\Users\mmo>

有什么想法吗?

podman-compose
3个回答
4
投票

基本上,这与将“podman-compose”安装到 WSL(或任何其他 Linux 发行版)中的过程相同:

  1. 安装适用于 Windows 的 Python:https://www.python.org/downloads/

  2. 创建虚拟环境并安装“podman-compose”:

    C:\somedir> python.exe -m venv venv-podman
    C:\somedir> venv-podman\Scripts\activate.bat
    (venv-podman) C:\somedir> pip install podman-compose
    (venv-podman) C:\somedir> podman-compose --version
    

您现在可以从所有其他目录调用

podman-compose
,因为它已被
activate.bat
放入您的搜索路径中。

如果退出此CMD(Windows命令提示符),您只需再次执行第二步(例如调用

activate.bat
)。

更新: 这是 shell 上的全部输入和输出:

D:\>C:\Python310\python.exe -m venv venv-podman

D:\>venv-podman\Scripts\activate

(venv-podman) D:\>pip install podman-compose
Collecting podman-compose
  Using cached podman_compose-1.0.6-py2.py3-none-any.whl (34 kB)
Collecting pyyaml
  Using cached PyYAML-6.0-cp310-cp310-win_amd64.whl (151 kB)
Collecting python-dotenv
  Using cached python_dotenv-1.0.0-py3-none-any.whl (19 kB)
Installing collected packages: pyyaml, python-dotenv, podman-compose
Successfully installed podman-compose-1.0.6 python-dotenv-1.0.0 pyyaml-6.0
WARNING: You are using pip version 21.2.3; however, version 23.1.2 is available.
You should consider upgrading via the 'D:\venv-podman\Scripts\python.exe -m pip install --upgrade pip' command.

(venv-podman) D:\>podman-compose --version
podman-compose version: 1.0.6
['podman', '--version', '']
using podman version: 4.5.1
podman-compose version 1.0.6
podman --version
podman version 4.5.1
exit code: 0

(venv-podman) D:\>

关于更新的帖子(python stacktrace):

podman.exe
在你的路径中吗?
podman --version
应该输出你的 podman 版本 - 无论你是否在 venv 中。安装 Podman Desktop 后,它应该在您的路径中。


0
投票

事实证明,运行 python 脚本(podman-compose 显然只是一个 python 脚本)的问题是 Windows 中的一个令人头疼的功能,即两个“Windows 执行别名”——无论出于何种原因——在我的系统上定义。当在命令行上调用“python”时,这会打开 Windows 应用商店,提供下载和安装 python,而不是实际启动 Python(我已经通过普通安装程序安装了它)。

令我非常困惑的是,为什么输入“python”会打开 Windows 应用商店,尽管 Python 安装目录位于路径上。我终于找到了该“现象”的解释以及如何删除该垃圾的解决方案:当我输入“python”时,CMD 打开 Windows 应用商店 删除/禁用此“别名”也解决了 podman-compose 的问题...


0
投票

如果您使用Windows,请执行以下步骤:

1、打开你的podman桌面

2、找到设置=>资源=>撰写=>设置

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.