进入docker容器中查看文件夹_如何查看在Docker容器中创建的文件?

I have a python script which generates outputs in a text file.I have built a docker image to run the script.While running the image its completing successfully but I cant see the output text file.

My Docker file is

From python:2.7

LABEL maintainer="ABC"

LABEL description="This Dockerfile creates MTA image"

WORKDIR /Temp

ADD script_v1.py connect.txt /Temp/

RUN pip install pexpect

CMD [ "python", "/Temp/script_v1.py" ]

In script_v1 script i have mentioned the /Temp location to generate he output

sys.stdout=open("/Temp/EXPORT_OP.txt","w")

I am running the image from windows docker host in Linux container mode.

解决方案

I see at least two simple ways of achieving what you want:

Use a bind mount. In short, you'll make a directory in your host filesystem available to the container, and you'll use its path to save the file. The output will be available in that folder.

Use docker cp after the container exits to copy the file from a location inside the container into your host filesystem.

Another way, which will not make the file available directly on your host filesystem, will be to docker exec -it bash, which will leave you with an open terminal inside the container, which you can use to cd into the correct directory and cat the file.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值