How do I copy files from host to Docker container

0 votes

I am stuck at this step. I have been trying to build a backup and restore solution for the Docker containers that we work with.

I have created a docker base image, ubuntu:base, and don't want  to rebuild it each time with a Docker file to add files to it.

I am trying to create a script which runs from the host machine and creates a new container using the ubuntu:base Docker image and then copies files into that container.

How do I copy files from the host to the container?

Can anyone help me with this?

Thanks

Aug 28, 2018 in DevOps & Agile by Damon Salvatore
• 5,980 points
1,366 views

1 answer to this question.

0 votes

Here is what you can use to copy a file from host to  container. The cp command can be used to copy files. One specific file can be copied like:

docker cp foo.txt mycontainer:/foo.txt
docker cp mycontainer:/foo.txt foo.txt

Multiple files contained by the folder src can be copied into the target folder using:

docker cp src/. mycontainer:/target
docker cp mycontainer:/src/. target

Here is what you can use for your reference: Docker CLI docs for cp

answered Aug 28, 2018 by Damon Salvatore
• 5,980 points

Related Questions In DevOps & Agile

+1 vote
2 answers

How do I run Apache server from Docker without mapping to a location?

If you're seeing a 500 error, that's ...READ MORE

answered Oct 18, 2018 in DevOps & Agile by lina
• 8,220 points
2,200 views
+1 vote
1 answer

How do I get a Docker container's IP address from the host?

Save your docker image as a tar ...READ MORE

answered Aug 29, 2018 in DevOps & Agile by shubham
• 7,340 points
1,002 views
+3 votes
2 answers

How do I set max lifetime for Docker Container?

There is one more way which you ...READ MORE

answered Oct 18, 2018 in DevOps & Agile by Kalgi
• 52,350 points
3,618 views
+14 votes
5 answers

How do I run a cron job inside a docker container

If you can SSH into your server ...READ MORE

answered Jul 27, 2018 in DevOps & Agile by Kalgi
• 52,350 points
16,554 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,720 views
0 votes
2 answers
0 votes
1 answer

How do I assign a port mapping to an existing Docker container?

Below are some steps which you can ...READ MORE

answered Sep 19, 2018 in DevOps & Agile by Damon Salvatore
• 5,980 points
9,311 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