docker - 由于使用 PowerShell 执行 Dockerfile 构建步骤,使用 Remote-Container 打开文件夹失败
问题描述
我希望使用 Remote-Containers 功能测试新的远程开发扩展。我抓取了示例 Python项目并使用该Remote-Containers: Open Folder in Container...
函数将其打开。
初始化过程开始正常,逐步完成一些 Docker 构建没有问题。Dockerfile 中的步骤 1-3 成功,然后步骤 4( Dockerfile 的第13/14行)抛出异常并退出,因为该RUN
命令包含一个AND_IF
运算符 ( &&
)。这是因为它作为子命令传递给不支持&&
.
我已按照说明准备我的系统以使用远程容器功能,包括将我的驱动器(C: 和 D:)添加到共享驱动器。
到目前为止我尝试过的故障排除:
- 在 Linux 和 Windows 容器之间切换
- 在 PowerShell、Git Bash 和 WSL (Ubuntu) 之间交换作为 Visual Code 的默认 shell (
terminal.integrated.shell.windows
) - 使用 Microsoft 的其他远程容器示例之一
- 使用一个简单的 Python 文件创建一个非常基本的项目并
Remote-Containers: Open Folder in Container...
再次尝试,选择python:3
目标 Docker 映像
上述步骤都没有产生任何不同的结果。
Docker Inspect 显示Config
->Shell
设置为:
"Shell":
[
"powershell",
"-Command",
"$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"
]
而Config
->Cmd
设置是:
"Cmd":
[
"powershell",
"-Command",
"$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';",
"apt-get update && apt-get -y install --no-install-recommends apt-utils 2>&1"
]
完整的容器配置在这里。
异常的原因很明显,但我无法辨别为什么 DockerfileRUN
指令会像上面那样传递给 PowerShell。
我在 Windows 10 (1809) 上运行 Visual Studio Code - Insiders (1.36.0-insider) 和 Docker Engine 18.09.2。
当第 4 步失败时,异常会产生以下错误(我已将前面的成功步骤包含在上下文中;为简洁起见,在第 2 步中将 pip 安装展平):
Setting up container for folder: d:\Development\vscode-remote-try-python-master
Run: docker build -f d:\Development\vscode-remote-try-python-master\.devcontainer\Dockerfile -t vsc-vscode-remote-try-python-master-486294f4d73f25a657ec08f53ff07d5f d:\Development\vscode-remote-try-python-master
Sending build context to Docker daemon 24.06kB
Step 1/13 : FROM python:3
---> 22a423a5db36
Step 2/13 : RUN pip install pylint
---> Running in 23380af29dd1
Successfully installed astroid-2.2.5 colorama-0.4.1 isort-4.3.20 lazy-object-proxy-1.4.1 mccabe-0.6.1 pylint-2.3.1 six-1.12.0 typed-ast-1.4.0 wrapt-1.11.1
Removing intermediate container 23380af29dd1
---> 5569fa48c9c5
Step 3/13 : ENV DEBIAN_FRONTEND=noninteractive
---> Running in 941086f674cb
Removing intermediate container 941086f674cb
---> b8b2fd47bdb1
Step 4/13 : RUN apt-get update && apt-get -y install --no-install-recommends apt-utils 2>&1
---> Running in defcc073adcf
At line:1 char:91
+ ... ; $ProgressPreference = 'SilentlyContinue'; apt-get update && apt-get ...
+ ~~
The token '&&' is not a valid statement separator in this version.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
ception
+ FullyQualifiedErrorId : InvalidEndOfLine
The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; apt-get update && apt-get -y install --no-install-recommends apt-utils 2>&1' returned a non-zero code: 1
Failed: Building an image from the Dockerfile.
Command failed: C:\Program Files\Docker\Docker\Resources\bin\docker.exe build -f d:\Development\vscode-remote-try-python-master\.devcontainer\Dockerfile -t vsc-vscode-remote-try-python-master-486294f4d73f25a657ec08f53ff07d5f d:\Development\vscode-remote-try-python-master
这是其他人的共同经历吗?将不胜感激任何解决方案或进一步排除故障的建议。
解决方案
如本GitHub 问题中所讨论的,此问题似乎是由于使用了 Windows 容器造成的。
是的,不幸的是,不支持 Windows 容器,并且鉴于 Docker 桌面的“Windows 容器模式”中使用 LCOW,考虑到它的实验状态,我们现在并不真正支持它。
LCOW 仍然存在差距,例如支持可能导致问题的单个文件绑定挂载,并且诸如 PostgreSQL 之类的东西被称为尚未工作。见这里和这里。
Windows 目前的建议主要是在例外情况下使用 LCOW:
何时使用 Moby VM
现在,我们向以下人员推荐运行 Linux 容器的 Moby VM 方法:
- 想要一个稳定的容器环境。这是 Windows 默认的 Docker。
- 运行 Windows 或 Linux 容器,但很少同时运行两者。
- 在 Linux 容器之间有复杂或自定义的网络要求。
- Linux 容器之间不需要内核隔离(Hyper-V 隔离)。
何时使用 LCOW
现在,我们向以下人群推荐 LCOW:
- 想测试我们的最新技术。
- 同时运行 Windows 和 Linux 容器。
- Linux 容器之间需要内核隔离(Hyper-V 隔离)。
推荐阅读
- html - 如何仅使用 bootstrap 4 在桌面和移动设备上给出列间隙?
- sql - 在 SQL 中将字符串转换为日期
- javascript - 带有 javascript 片段的 VS Code Intellisense html 标签
- python - 将带参数的函数结果存储到变量中
- nearprotocol - (AssemblyScript + ReactJS)无法在网络共享测试上为帐户 test.near 签署交易
- c++ - 如何通过 C++ 为 v lang 创建库
- java - 验证重复项 - 在序列化类 Java 中比较 .bin 文件中的对象
- flutter - flutter 2.5.1升级后运行flutter项目出错
- swiftui - Swiftui:菜单项或选择器中的多行
- unreal-engine4 - 虚幻编辑器的问题