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

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

问题描述

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



我执行此操作的方法是将该主机目录挂载为数据卷,即 docker run -v / usr / share / nginx / reports --name my-container com。 container / my-container



但是,当我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天全站免登陆