---
title: 'How to copy data from a host to Docker and from Docker to a host | Zomro'
description: 'Sometimes you need to send files from the host machine to the Docker container, and from the container to the host. In this article we can see how to do it.'
image: 'https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669746477_1.png'
---

![opened image]()

  * [Zomro](https://zomro.com/)
  * [FAQ](https://zomro.com/blog/faq/)
  * How to copy data from a host to Docker and from Docker to a host 



# How to copy data from a host to Docker and from Docker to a host

14-11-2022

As we saw from the previous articles, Docker can simplify the deployment of different applications and their execution.  
  
But sometimes you need to send files from the host machine to a Docker container, and from the container to the host.  
  
In this article, we will see how to do this.  


  
The following commands assume that you already have Docker installed. If not, you can learn how to do it in the articles: "[How to install Docker on Centos 7](https://zomro.com/rus/blog/faq/287-kak-ustanovit-docker-na-centos-7)" or "[How to install Docker on Ubuntu 20.04](https://zomro.com/rus/blog/faq/286-kak-ustanovit-docker-na-ubuntu-2004)".  


## Copying files from the host system to the Docker container.

  
To copy to and from Docker, we will use the **docker cp** utility.  
  
The **docker cp** utility copies the contents of the source to the destination.  
  
You can copy from the container's file system to the local computer or vice versa, from the local file system to the container.  
  
  
Example: **Local host - > Container**
    
    
    docker cp <path to file on host machine> containerid:<path to file in container>
    

  
Example: Container -> Local host
    
    
    docker cp containerid:<path to file on host machine> <path to file on host machine>
    

  
  
Let's see this in action with a simple example of a Docker image of Nginx.  
  
We can use the following command:
    
    
    docker run -d --name nginx_copy nginx
    

  
where:  
**nginx_copy** \- container name (you can use any)  
**nginx** \- image name on Docker Hub that we will use  
  
  
If you don't have this container on your server, wait for it to be downloaded.   
  
![How to copy data from a host to Docker and from Docker to a host](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669746477_1.png)  


Now let's enter the container to see/find where or which file to copy.
    
    
    docker exec -it nginx_copy /bin/bash
    

  
Now let's display the contents of the /etc/nginx folder in the terminal.
    
    
    ls -la  /etc/nginx/
    

  
For example, let's say we need to copy the nginx.conf configuration file and we know that it is located at /etc/nginx/nginx.conf. To do this, enter the following command:
    
    
    docker cp nginx_copy:/etc/nginx/nginx.conf ~/nginx.conf
    

  
Where:  
  
**nginx_copy** \- the container from which we are copying;  
**/etc/nginx/nginx.conf** \- the path to the file to be copied;  
**~/nginx.conf** \- the destination and file name (you can specify a different file name)  
  
Now let's see the result:
    
    
    ls -la
    

  
![How to copy data from a host to Docker and from Docker to a host-1](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669746815_2.png)  
As we can see, the file was successfully copied to the host. Now we can modify it and then upload it back.

## **How to copy a file to a container.**

  
Suppose we now need to copy the modified nginx.conf file back to the container. To do this, we can use the following construction:
    
    
    docker cp ~/nginx.conf nginx_copy:/etc/nginx/nginx.conf_cp
    

  
If everything is entered correctly, we will be able to see this file in the container.  
  
Enter the container:
    
    
    docker exec -it nginx_copy /bin/bash
    

  
And display the contents of the /etc/nginx directory:
    
    
    ls -la
    

  
![How to copy data from a host to Docker and from Docker to a host-2](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669747156_3.png)  


As we can see, the new file has been copied inside the container.  
  
Using the same principle, you can transfer data from the container to the host and vice versa.

​​​​​​​  
We also suggest you other useful articles:

  * [List of important commands for working with Docker-compose](https://zomro.com/blog/faq/304-spisok-vazhnyh-komand-dlja-raboty-s-docker-compose)
  * [How to Deploy Any Version of PHP in Docker-Compose](https://zomro.com/blog/faq/348-how-to-deploy-any-version-of-php-in-docker-compose-for-beginners)
  * [How to connect to a Docker container via sFTP](https://zomro.com/blog/faq/306-how-to-connect-to-a-docker-container-via-sftp)



Similar articles:

[How to Install and Configure IIS FTP Server on Windows Server 2019](https://zomro.com/blog/faq/315-kak-ustanovit-i-nastroit-ftp-server-iis-na-windows-server-2019) [How to view Centos 7 server logs](https://zomro.com/blog/faq/350-how-to-view-centos-7-server-logs) [How to raise OpenSSH on Windows 2016](https://zomro.com/blog/faq/405-how-to-raise-openssh-on-windows-2016) [Installing the Pterodactyl Control Panel (Ubuntu)](https://zomro.com/blog/faq/358-installing-the-pterodactyl-control-panel-ubuntu) [Enabling HTTP2 in ISPmanager](https://zomro.com/blog/faq/202-vkljuchenie-http2-v-ispmanager)

[ Dedicated servers from €88.80/mon ](/dedicated-servers)
