Discover the top-rated web hosting providers with trusted reviews, expert comparisons, and the latest deals.
Select Currency 7 Currencies
Select Region 9 Editions
VPS Hosting

VPS (Virtual Private Server) hosting is highly popular these days, and there are VPS plans available for small, medium, and even huge business websites!

In comparison to dedicated servers, VPS is pretty low-cost, and your enterprise remains independent if you buy a VPS plan!

Cheap Hosting

If you're starting your first website, you want to spend less on premium web hosting, worry about website performance, or know anything about CPU cores. You only need to consider usability, customer service, and long-term scalability.

Our experts have compiled a list of cheap hosting providers that combine affordability and reliability.

TheWebHostingDIR
DISCUSSION Shared Hosting

How do I Copy files from host to a Docker container?

Asked by Anonymous
8 years ago
1,920 views
1 answer

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

I am trying to build a backup and restore solution for the Docker containers. I have Docker base image that I have created, ubuntu:base, and do not want have to rebuild it each time with a Docker file to add files to it. I want to create a script that runs from the host machine and creates a new container using the ubuntu:base Docker image and then copies files into that container.

1 Answer

A
Anonymous
answered 7 years ago

You can use the cp command to copy files. One specific file can be copied like:

docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-

docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH

==============================

docker cp foo.txt mycontainer:/foo.txt

docker cp mycontainer:/foo.txt foo.txt

For example, mycontainer is a container ID, not an image ID.

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

Reference URL : https://docs.docker.com/engine/reference/commandline/cp/

In Docker versions prior to 1.8 it was only possible to copy files from a container to the host. Not from the host to a container.

Your Answer

Please share accurate, constructive advice to help other community members.

Posting as Guest / Community Member
Live Preview

Posts are reviewed by moderation to maintain community quality and eliminate spam.

Link copied to clipboard!

Hosting Companies insights