docker的ubuntu容器中如何获取文件信息

hillseas 2015-02-05 04:52:28
在容器中查询文件系统信息如下:
root@27755d922ffb:~# df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 18G 15G 2.1G 88% /
none 18G 15G 2.1G 88% /
tmpfs 998M 0 998M 0% /dev
shm 64M 0 64M 0% /dev/shm
/dev/disk/by-uuid/f65dfc67-4152-4da0-9a6e-fcc2b822a574 18G 15G 2.1G 88% /etc/hosts
tmpfs 998M 0 998M 0% /proc/kcore

root@27755d922ffb:~# tune2fs -l rootfs
tune2fs 1.42.9 (4-Feb-2014)
tune2fs: No such file or directory while trying to open rootfs
Couldn't find valid filesystem superblock.
请问为什么看不到文件系统信息?
正常情况下,不应该是类似于/dev/sda1之类的名字吗,为什么是rootfs


另外,编写如下程序:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#define __USE_GNU 1
#include <fcntl.h>

int main()
{
int ret_num = 0;
char *szPath = "./test.txt";
int dwFlags = O_RDWR | O_NOATIME | O_CREAT | O_SYNC;

printf("open function test\n");

ret_num = open("./test1.txt", dwFlags, 00600);

if (ret_num == -1)
printf("test1(no O_DIRECT) fail system errno %d\n",errno);
else
printf("test1(no O_DIRECT) Success\n");

ret_num = 0;
dwFlags |= O_DIRECT;
ret_num = open("./test2.txt", dwFlags, 00600);

if (ret_num == -1)
printf("test2(have O_DIRECT) fail system errno %d\n",errno);
else
printf("test2(have O_DIRECT) Success\n");

printf("open function test finish\n");
}

在ubuntu服务器上执行结果如下:
root@ubuntu:~# gcc test.c -o aa
root@ubuntu:~# ./aa
open function test
test1(no O_DIRECT) Success
test2(have O_DIRECT) Success
open function test finish

在ubuntu容器中执行结果如下:
root@27755d922ffb:~# gcc test.c -o aa
root@27755d922ffb:~# ./aa
open function test
test1(no O_DIRECT) Success
test2(have O_DIRECT) fail system errno 2
open function test finish

请问有什么 办法解决这个差异?谢谢!
...全文
267 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
alinly 2015-09-15
  • 打赏
  • 举报
回复
docker 应该是取宿主机器上的一个目录作为/ 所有没有/dev/sdx.

1,163

社区成员

发帖
与我相关
我的任务
社区描述
Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux 机器上,也可以实现虚拟化。
社区管理员
  • Docker
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧