-1

I have downloaded a repository from Docker Hub by running the Docker Pull command. This was successful but I now need to add a new file directory so that I can copy a file from my local machine. I think I have managed to copy the file to the image but I do not know how to put it in the new directory.

Could someone help with some instructions on how to copy a file from my local machine to a new file directory on the image?

Darren
  • 9
  • 6

2 Answers2

1

If you are creating a new image and needs to copy files to the image you must use COPY a file and VOLUME to map a volume, docs will help you most

If you are just running an image and needs to map a local directory to the container you should use volumes (--v) to achive that, read this

Vinicius Katata
  • 932
  • 3
  • 7
  • Thanks for the reply. I am still a little confused as to how to go about this. The instructions I have been given is that two configuration files must be placed in a folder that is mounted in the Docker container, and the configuration files should be put in ./example/. I cannot run the image without the configuration files. – Darren Apr 18 '21 at 17:49
  • When you execute the run command, you could include: `docker run ... --volume=DIR_IN_YOUR_PC:DIR_IN_CONTAINER`, that will map the directory from your PC (aka host) to containers one you configurate – Vinicius Katata Apr 18 '21 at 17:58
0

There is the command that you should use docker cp

Example of usage:

docker cp local-file.jar <CONTAINER>:/home/app.jar

A similar question with many answers How to copy files from host to Docker container?

Andrzej Sydor
  • 1,373
  • 4
  • 13
  • 28
  • Thanks. I have run the command but I get the following error: `PS C:\Users\Darren\OneDrive\Desktop> docker cp micro.conf 836539dcf6e1:/example/micro.conf Error: No such container:path: 836539dcf6e1:\example PS C:\Users\Darren\OneDrive\Desktop>` – Darren Apr 18 '21 at 18:29
  • Do I get the error because the directory does not exist? – Darren Apr 18 '21 at 18:32
  • @Darren that is possible. Please create the directory firstly. – Andrzej Sydor Apr 18 '21 at 21:06
  • 1
    Thanks for the reply. I am trying to figure out how to create a directory at the moment! – Darren Apr 18 '21 at 21:57
  • @Darren, just to connect to the container than mkdir /example. – Andrzej Sydor Apr 19 '21 at 06:17
  • @Darren here another question with answers on how to get into container: https://stackoverflow.com/questions/30172605/how-do-i-get-into-a-docker-containers-shell – Andrzej Sydor Apr 19 '21 at 06:19