简体   繁体   English

如何使用 docker 卷和 ubuntu 映像来访问从 AWS S3 下载的文件?

[英]How can I use docker volume with ubuntu image to access a downloaded file from AWS S3?

I want to copy a file from AWS S3 to a local directory through a docker container.我想通过 docker 容器将文件从 AWS S3 复制到本地目录。 This copying command is easy without docker, I can see the file downloaded in the current directory.这个复制命令很简单,不用docker,我可以在当前目录看到下载的文件。 But the problem is with docker that I don't even know how to access the file.但问题出在 docker 上,我什至不知道如何访问该文件。

Here is my Dockerfile:这是我的 Dockerfile:

FROM ubuntu
WORKDIR "/Users/ezzeldin/s3docker-test"
RUN apt-get update
RUN apt-get install -y awscli
ENV AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
ENV AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
CMD [ "aws", "s3", "cp", "s3://ezz-test/s3-test.py", "." ]

The current working folder that I should see the file downloaded to is s3docker-test/ .我应该看到文件下载到的当前工作文件夹是s3docker-test/ This is what I'm doing after building the Dockerfile to mount a volume myvol to the local directory这是我在构建 Dockerfile 以将卷 myvol 挂载到本地目录后所做的事情

docker run -d --name devtest3 -v $PWD:/var/lib/docker/volumes/myvol/_data ubuntu

So after running the image I get this: download: s3://ezz-test/s3-test.py to./s3-test.py which shows that the file s3-test.py is already downloaded, but when I run ls in the interactive terminal I can't see it.所以在运行图像后我得到这个: download: s3://ezz-test/s3-test.py to./s3-test.py这表明文件s3-test.py已经下载,但是当我运行时在ls终端中我看不到它。 So how can I access that file?那么如何访问该文件呢?

Looks like you are overriding containers folder with your empty folder, when you run -v $PWD:/var/lib/docker/volumes/myvol/_data .当您运行-v $PWD:/var/lib/docker/volumes/myvol/_data时,看起来您正在用空文件夹覆盖容器文件夹。

Try to simply copy the files from container to host fs by running:尝试通过运行简单地将文件从容器复制到主机 fs:

docker cp \
  <containerId>:/Users/ezzeldin/s3docker-test/s3-test.py \
  /host/path/target/s3-test.py

You could perform this command even on downed container.您甚至可以在宕机的容器上执行此命令。 But first you will have to run it without folder override:但首先你必须在没有文件夹覆盖的情况下运行它:

docker run -d --name devtest3 ubuntu

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM