×

Search anything:

Copy file from docker to local host

Binary Tree book by OpenGenus

Open-Source Internship opportunity by OpenGenus for programmers. Apply now.

In this article at OpenGenus, we have explained how to copy a file from a Docker container to local host or system. This command is "docker cp container-id:/path/to/file .".

Table of contents:

  1. Steps to Copy file from docker to local host

Steps to Copy file from docker to local host

There are two steps to copy a file from a Docker container to the local host or system so that you can use the file outside of Docker:

  1. Get the container ID of Docker

To get the list of ID of all Docker container in your system, use this command:

sudo docker container ls

The output will be like:

CONTAINER ID   IMAGE                                                  COMMAND                  CREATED          STATUS          PORTS     NAMES
055baag9e572   quay.io/pypa/opengenus   "opengenus"   12 minutes ago   Up 12 minutes             opengenus_env

Identify the ID of your container. In our case, it is 055baag9e572.

If you are within the concerned docker container, the ID is mentioned in the terminal as well:

[root@<container-id> DIRECTORY]#

Like:

[root@055baag9e572 DIRECTORY]#
  1. Copy file from docker

The command to copy a file from Docker to local host is:

sudo docker cp <container_id>:/path/to/file .

In our case, the command will be:

sudo docker cp 055baag9e572:/home/opengenus.txt .

With this article at OpenGenus, you must have the complete idea of how to copy a file from a docker container to local host.

Copy file from docker to local host
Share this