Copying files from host to Docker container

+5 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,060 points
349,999 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)

Ready to level up your Docker skills? Enroll now in our comprehensive Docker Course!

answered Jul 18, 2018 by sunshine
• 1,300 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 29, 2020 by Pistle
• 1,000 points
+2 votes

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,460 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 34,312 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 28, 2018 in Docker by Damon Salvatore
• 5,980 points
28,623 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,620 points
3,566 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 17, 2018 in Docker by Sophie may
• 10,620 points
8,917 views
+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,020 points
2,752 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 12, 2020 in Docker by MD
• 95,460 points
2,775 views
0 votes
1 answer

How to find a Docker container IP address from the command line?

Hi@akhtar, You can use the docker inspect command ...READ MORE

answered Sep 4, 2020 in Docker by MD
• 95,460 points
4,080 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP