创建文件或将文件从 docker 容器复制到主机

create the file or copy the file from docker container to host

下面是我的代码:

docker container run -it ubuntu /bin/bash -c "touch /root/test.txt"

我想要的是在我的主机上创建这个文件。有人可以帮帮我吗?

一种选择是从容器中的主机挂载目录。触摸容器内创建装载位置的 .txt 文件。

此示例将在 docker 主机的工作目录中创建 test.txt 文件:

docker run -it -v $(pwd):/root/mout-from-host ubuntu /bin/bash -c "touch /root/mout-from-host/test.txt"
ls
test.txt <<--file on host, created by the container