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 27, 2018 in DevOps & Agile by Damon Salvatore
• 5,510 points
119 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 27, 2018 by Damon Salvatore
• 5,510 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,160 points
86 views
0 votes
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
• 6,890 points
62 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
• 45,960 points
449 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
• 45,960 points
3,472 views
0 votes
1 answer
0 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
• 57,300 points
263 views
0 votes
2 answers
0 votes
1 answer