Docker Community Forums

Share and learn in the Docker community.

Unable to copy files from local to docker container

I want to pass the content of some file to my docker image, basically the .aws credential and other file. Is there a way out?

Please find the code as below:

docker build -t TestImage . --build-arg AWSPathConfig=/home/ubuntu/.aws/config --build-arg AWSPathCredential=/home/ubuntu/.aws/credentials --no-cache=true

here AWSPathConfig and AWSPathCredential are the aws config and credential content

Right now they are just strings that happen to match filenames on your host.

Secrets should never, never, never ever be build into an image. Neither for an artifact repo, nor for a cli tool like aws cli or kubectl… never ever.

If you are trying to copy the directory public-html into the directory /usr/local/apache2/htdocs to have an …/htdocs/public-html/ directory, then use the following:

COPY public-html/ /usr/local/apache2/htdocs/public-html/
By default, copying a directory will copy the contents of that directory, so you need to name it in the target for the directory to appear.

Edit: Your run command contains a volume that will replace the image contents of this directory:

docker run -d --name apws -v /Users/ankitsahu/workspace/docker_practice/public-html:/usr/local/apache2/htdocs/ -p 80:80 apache
If you want to see what’s inside the image, do not use the volume:

docker run -d --name apws -p 80:80 apache
If instead you want to use the volume, then modify the contents of /Users/ankitsahu/workspace/docker_practice/public-html on your docker host.