Copying files from host to Docker container

+3 votes

I am trying to build a backup and restore solution for the Docker containers. How can I copy files from the host to the container?

Appreciate the help.

Jul 18, 2018 in Docker by Nilesh
• 7,020 points
227,218 views

3 answers to this question.

+1 vote

For copying the files from the host to the docker container :

  1. First, set the path in your localhost to where the file is stored.
  2. Next set the path in your docker container to where you want to store the file inside your docker container.
  3. Then copy the file which you want to store in your docker container with the help of CP command. 

ex: sudo docker cp /home/(name)/(folder_name)/(file_name)  (container_id):/(to_the_place_you_want_the_file_to_be)

answered Jul 18, 2018 by sunshine
• 1,280 points
When I run docker-compose up all the changes are rolled back and nothing happens
Are you trying to copy files from host to container using docker-compose? You can simply mount your local file with your container.
0 votes

P.S The docker cp command works similar to the SSH scp command.

  1. Container -> Local HostCopy file or folder from a docker container to the local file system. Terminal.
  2. Local Host -> ContainerCopy file or folder from the local file system to a docker container, it works the same. Terminal.
Hope this will help
answered Aug 28, 2020 by Pistle
• 1,000 points
+1 vote

Hi,

You can use the docker cp command to copy files from host to docker container.

$ docker cp /hostfile  (container_id):/(to_the_place_you_want_the_file_to_be)
answered Dec 9, 2020 by MD
• 95,180 points

Related Questions In Docker

+4 votes
4 answers

How To Access a Service on Host From a Docker Container?

Adding to kalgi's answer, You can also ...READ MORE

answered Oct 16, 2018 in Docker by lina
• 8,220 points

edited Oct 16, 2018 by lina 21,800 views
+1 vote
2 answers

How do I copy a file from docker container to host?

Here is a way which you can ...READ MORE

answered Aug 27, 2018 in Docker by Damon Salvatore
• 5,980 points
24,799 views
0 votes
1 answer

How to copy files from docker container to local system?

Hi@akhtar, You can copy your file from docker ...READ MORE

answered May 11, 2020 in Docker by MD
• 95,180 points
1,129 views
0 votes
1 answer

How to run a docker command from inside the container?

You must have come across the /var/run/docker.sock file, ...READ MORE

answered Jun 28, 2018 in Docker by Sophie may
• 10,550 points
1,909 views
0 votes
1 answer

How to obtain the Docker container's IP address from the host?

This can be done by executing the ...READ MORE

answered Jul 16, 2018 in Docker by Sophie may
• 10,550 points
7,221 views
+1 vote
2 answers
+2 votes
1 answer
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,120 points
1,149 views