Skip to content
Home ยป How to Move a File/Folder From the Server to the Container And Vice Versa?

How to Move a File/Folder From the Server to the Container And Vice Versa?

The previous article explained how to access a container in Docker. Now, I need to move a file/folder from the server to the container and vice versa.

 

Problem

How to move a file/folder from the server to the container and vice versa?

 

Solution

These are how to move a file/folder from the server to the container and vice versa:

A. Move from the server to the container

To move a file from the server to the container, use the format below:

docker cp src_path container:dest_path

 

For example, I want to move the nginx.tgz file from the server to the webapp1 container in the folder /home, so I use the command below:

docker cp nginx.tgz webapp1:/home

 

And the file will move to the /home folder in the container, like in the image below:

Move the file from the server to the container

 

B. Move from the container to the server

To move a file from the server to the container, use the format below:

docker cp container:src_path dest_path

 

For example, you want to move the docker-entrypoint.sh file in the container to the server in the folder /tmp, use the command below to move the file:

docker cp webapp1:docker-entrypoint.sh /tmp

 

And the file should be transferred to the folder /tmp on the server as shown below:

move a file/folder from the server to the container and vice versa
Move the file from the container to the server

 

Note

You can move the folder and its contents from the server to the container and vice versa by using the format above without the need to add the -r option, as shown in the image below:

move a file/folder from the server to the container and vice versa
Move the folder into and out of the container

 

WARNING
You cannot move more than one file or folder from the server to the container or vice versa.

 

References

youtube.dimas-maryanto.com
docs.docker.com
mkyong.com

image_pdfimage_print
Visited 34 times, 1 visit(s) today
Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *