运行 Docker 在 WSL 上未执行 "RUN" 指令,也未正确构建

Running Docker on WSL not executing "RUN" instruction, nor building properly

我安装了 Docker Desktop,并按照以下指南设置所有内容以使用 WSL。

https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly

起初尝试构建图像时出现以下错误。 命令:“docker build -t hello .”

我通过将其放入我的控制台来解决这个问题:

export DOCKER_BUILDKIT=0
export COMPOSE_DOCKER_CLI_BUILD=0

我现在可以成功构建/运行 我的 docker 图像:

我的控制台输出了“test”,但问题是没有创建 txt 文件。应该是因为我得到了一个输出并且“cat”正在从文件中读取,但它没有出现在我 运行 图像所在的文件夹中?我也无法在其他任何地方找到它。有什么建议吗?

您的 Dockerfile 在容器本身内部创建 helloWorld.txt 文件,并且它不会在您的本地文件系统上可见。如果您构建了图像并将其标记为 hello,则可以通过以下方式将 shell 放入系统:

docker run -it hello:latest /bin/bash

这会给你一个 bash shell 进入你应该能够查看输出的机器:

$ docker run -it hello:latest /bin/bash
root@88a2b4c7d88e:/# ls
bin  boot  dev  etc  helloWorld.txt  home  ...