与用户的本地系统文件路径的容器通信

huangapple go评论85阅读模式
英文:

Container communication with user's local system filepath

问题

我正在使用golang和aws S3 SDK for golang执行文件传输服务。目标是将文件上传到S3并从S3下载到用户的系统。我已经能够做到这一点,但现在我需要使用Docker将我的应用程序容器化。由于Docker容器将拥有自己的本地文件系统,我担心我的golang代码会将文件下载到Docker的本地文件系统而不是用户的本地文件系统。有人可以指导我如何实现将文件下载到用户的本地系统而不是Docker文件系统吗?
提前感谢。

英文:

I am performing file transfer service using golang and aws S3 SDK for golang. The aim is to upload files to S3 and download files from S3 to user's system. I am able to do it but now, I need to containerize my application using docker. Since docker container will have its own local file system, I am afraid my code in golang would download files to docker local file system instead of user's local file system. Can anyone please guide me on how to achieve downloading files to user's local system instead of docker file system?
Thanks in advance.

答案1

得分: 1

为了实现您的请求,您需要将Docker文件系统与用户的文件系统绑定。一种方法是使用'volumes'。还可以参考链接https://docs.docker.com/storage/获取更多信息。

英文:

Inorder to achieve your request, you have to bind the docker file system with the user's file system. One way is to use 'volumes'. Also refer to the link https://docs.docker.com/storage/ for more information.

答案2

得分: 1

简而言之,你需要使用volumes

例如,如果你想在Docker中使用aws-cli,并从S3下载文件到当前路径,你需要运行以下命令:

docker run --rm -it -v $(pwd):$(pwd) -v ~/.aws:/root/.aws -e AWS_PROFILE amazon/aws-cli:2.0.6 s3 cp s3://<bucket_name>/<file> $(pwd)/.

我知道你正在使用一个应用程序来获取这些文件,但这个示例可以帮助你理解Docker中的工作原理。基本上,我们将当前目录映射到Docker容器的主目录,你只需要调整应用程序使用的卷的路径即可。

英文:

TL;DR you need to use volumes.

For example, if you want to use aws-cli from docker, and download a file from S3 to the current path, you need to run:

docker run --rm -it -v $(pwd):$(pwd) -v ~/.aws:/root/.aws -e AWS_PROFILE amazon/aws-cli:2.0.6 s3 cp s3://&lt;bucket_name&gt;/&lt;file&gt; $(pwd)/.

I know you are using an application to get those files, but this example can help you to understand how the things works in Docker. Basically we are mapping our current directory with the home folder of the docker container, you just need to adapt the path of the volumes that your application uses.

huangapple
  • 本文由 发表于 2021年10月12日 13:19:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/69535414.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定