docker container not able to write on host machine

2019-09-05 14:50发布

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

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

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

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

标签: ubuntu docker
1条回答
一纸荒年 Trace。
2楼-- · 2019-09-05 15:15

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
查看更多
登录 后发表回答