• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

“docker cp” Command Examples

by admin

The “docker cp” command is a useful feature of Docker that allows users to copy files or directories between the host system and a container’s filesystem. It provides a straightforward way to transfer files and data between the host and the container, facilitating tasks such as copying configuration files, logs, or any other necessary data.

Using the “docker cp” command, you can specify the source and destination paths to copy files in either direction: from the host system to the container or from the container to the host system. This flexibility allows for easy data exchange and synchronization between the two environments.

To copy a file or directory from the host system to a container, you need to provide the path of the source file or directory on the host and the destination path within the container. Docker will then initiate the copy process, transferring the specified files or directories into the container.

Conversely, if you want to copy a file or directory from a container to the host system, you need to specify the source path within the container and the destination path on the host. Docker will then perform the copy operation, retrieving the specified files or directories from the container and placing them on the host system.

The “docker cp” command works with both running and stopped containers. For running containers, you need to specify the container’s ID or name along with the source and destination paths. If the container is stopped, you can still copy files by providing the container’s ID or name as an argument.

It’s important to note that the “docker cp” command operates on the container’s filesystem and not on individual running processes within the container. Therefore, you can copy files even if the corresponding process is not running.

docker cp Command Examples

1. Copy a file or directory from the host to a container:

# docker cp /path/to/file_or_directory_on_host container_name:/path/to/file_or_directory_in_container

2. Copy a file or directory from a container to the host:

# docker cp container_name:/path/to/file_or_directory_in_container /path/to/file_or_directory_on_host

3. Copy a file or directory from the host to a container, following symlinks (copies the symlinked files directly, not the symlinks themselves):

# docker cp --follow-link /path/to/symlink_on_host container_name:/path/to/file_or_directory_in_container

Summary

Overall, the “docker cp” command simplifies the process of copying files and directories between the host system and a Docker container. It provides a convenient way to transfer data, configuration files, logs, or any other necessary files, enabling seamless interaction and data exchange between the host and the container environments.

Filed Under: Linux

Some more articles you might also be interested in …

  1. killall: command not found
  2. How to Create and Query a BTRFS File System
  3. ethtool: command not found
  4. tvservice: command not found
  5. ack – A search tool like grep, optimized for developers (Command Examples)
  6. pw-record Command Examples in Linux
  7. cmatrix: Shows a scrolling Matrix like screen in the terminal
  8. aurman Command Examples
  9. gnmic Command Examples
  10. esptool.py: Bootloader utility for Espressif chips (e.g. ESP8266)

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright