如何将数据从 Docker 容器写入主机文件系统 [英] How to write data to host file system from Docker container

查看:43
本文介绍了如何将数据从 Docker 容器写入主机文件系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Docker 容器,它正在运行一些代码并创建一些 HTML 报告.我希望将这些报告发布到主机上的特定目录中,即在 /usr/share/nginx/reports

我这样做的方法是将该主机目录挂载为数据卷,即 docker run -v/usr/share/nginx/reports --name my-container com.containers/my-容器

但是,当我通过 ssh 进入主机并检查目录 /usr/share/nginx/reports 的内容时,我在那里看不到任何报告数据.

我做错了吗?

宿主机是Ubuntu服务器,Docker容器也是Ubuntu,这里没有boot2docker怪癖.

解决方案

来自

I have a Docker container which is running some code and creating some HTML reports. I want these reports to be published into a specific directory on the host machine, i.e. at /usr/share/nginx/reports

The way I have gone about doing this is to mount this host directory as a data volume, i.e. docker run -v /usr/share/nginx/reports --name my-container com.containers/my-container

However, when I ssh into the host machine, and check the contents of the directory /usr/share/nginx/reports, I don't see any of the report data there.

Am I doing something wrong?

The host machine is an Ubuntu server, and the Docker container is also Ubuntu, no boot2docker weirdness going on here.

解决方案

From "Managing data in containers", mounting a host folder to a container would be:

docker run -v /Users/<path>:/<container path>

(see "Use volume")

Using only -v /usr/share/nginx/reports would declare the internal container path /usr/share/nginx/reports as a volume, but would have nothing to do with the host folder.

This is one of the type of mounts available:

这篇关于如何将数据从 Docker 容器写入主机文件系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆