docker容器无法在主机上写入 [英] docker container not able to write on host machine

查看:153
本文介绍了docker容器无法在主机上写入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果运行以下代码,则可以将csv文件转换为所需的格式。

If I run the following code, I can convert the csv file into a format that I require.

import csv
import json

csvfile = open('/tmp/head.csv', 'r')
jsonfile = open('/tmp/file.json', 'w')

fieldnames = ("user","messageid","destination","col1", "col2", "code1","code2", "mydate", "status")

reader = csv.DictReader( csvfile, fieldnames)

for row in reader:
    jsonfile.write(json.dumps(row))

当我在命令提示符下运行代码时,它就起作用了。

When I run the code at command prompt, it works.

python covert.py

但是如果我创建docker容器,ubuntu拒绝写入磁盘。

But if I create docker container, ubuntu refused to write to the disk.

alias python34='docker run -i   -v "$(pwd)":/tmp/  --rm shantanuo/pyrun:3.4 python "$@"'

python34 /tmp/convert.py

我遇到了分段错误错误。我尝试使用

I got segmentation fault error. I tried disabling ubuntu firewall using

sudo ufw disable

我尝试移除装备。但是我仍然无法通过python容器写入主机的/ tmp /文件夹。

I tried removing apparmour. But I am still not able to write to /tmp/ folder of host machine through python container.

这是Ubuntu特有的问题。我可以在Amazon Linux ec2实例上使用相同的别名。

This is ubuntu specific issue. I am able to use the same alias on Amazon Linux ec2 instance.

推荐答案

这是因为我以前使用的容器(pyrun)使用未针对处理大文件进行优化。当我使用默认的python映像时,它起作用了。

This was because the container (pyrun) that I was using was not optimized to handle large files. When I used the default python image, it worked.

docker run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp python:3 python convert.py

这篇关于docker容器无法在主机上写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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