Home > Blockchain >  Container communication with user's local system filepath
Container communication with user's local system filepath

Time:10-13

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.

CodePudding user response:

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.

CodePudding user response:

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://<bucket_name>/<file> $(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.

  • Related