github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/docs/source/markdown/podman-cp.1.md (about)

     1  % podman-cp(1)
     2  
     3  ## NAME
     4  podman\-cp - Copy files/folders between a container and the local filesystem
     5  
     6  ## SYNOPSIS
     7  **podman cp** [*options*] [*container*:]*src_path* [*container*:]*dest_path*
     8  
     9  **podman container cp** [*options*] [*container*:]*src_path* [*container*:]*dest_path*
    10  
    11  ## DESCRIPTION
    12  **podman cp** allows copying the contents of **src_path** to the **dest_path**. Files can be copied from a container to the local machine and vice versa or between two containers.
    13  If `-` is specified for either the `SRC_PATH` or `DEST_PATH`, one can also stream a tar archive from `STDIN` or to `STDOUT`.
    14  
    15  The containers can be either running or stopped and the *src_path* or *dest_path* can be a file or directory.
    16  
    17  *IMPORTANT: The **podman cp** command assumes container paths are relative to the container's root directory (`/`), which means supplying the initial forward slash is optional and therefore sees `compassionate_darwin:/tmp/foo/myfile.txt` and `compassionate_darwin:tmp/foo/myfile.txt` as identical.*
    18  
    19  Local machine paths can be an absolute or relative value.
    20  The command interprets a local machine's relative paths as relative to the current working directory where **podman cp** is run.
    21  
    22  Assuming a path separator of `/`, a first argument of **src_path** and second argument of **dest_path**, the behavior is as follows:
    23  
    24  **src_path** specifies a file:
    25    - **dest_path** does not exist
    26      - the file is saved to a file created at **dest_path** (note that parent directory must exist).
    27    - **dest_path** exists and is a file
    28      - the destination is overwritten with the source file's contents.
    29    - **dest_path** exists and is a directory
    30      - the file is copied into this directory using the base name from **src_path**.
    31  
    32  **src_path** specifies a directory:
    33    - **dest_path** does not exist
    34      - **dest_path** is created as a directory and the contents of the source directory are copied into this directory.
    35    - **dest_path** exists and is a file
    36      - Error condition: cannot copy a directory to a file.
    37    - **dest_path** exists and is a directory
    38      - **src_path** ends with `/`
    39        - the source directory is copied into this directory.
    40      - **src_path** ends with `/.` (i.e., slash followed by dot)
    41        - the content of the source directory is copied into this directory.
    42  
    43  The command requires **src_path** and **dest_path** to exist according to the above rules.
    44  
    45  If **src_path** is local and is a symbolic link, the symbolic target, is copied by default.
    46  
    47  A *colon* ( : ) is used as a delimiter between a container and its path, it can also be used when specifying paths to a **src_path** or **dest_path** on a local machine, for example, `file:name.txt`.
    48  
    49  *IMPORTANT: while using a *colon* ( : ) in a local machine path, one must be explicit with a relative or absolute path, for example: `/path/to/file:name.txt` or `./file:name.txt`*
    50  
    51  Using `-` as the **src_path** streams the contents of `STDIN` as a tar archive. The command extracts the content of the tar to the `DEST_PATH` in the container. In this case, **dest_path** must specify a directory. Using `-` as the **dest_path** streams the contents of the resource (can be a directory) as a tar archive to `STDOUT`.
    52  
    53  Note that `podman cp` ignores permission errors when copying from a running rootless container.  The TTY devices inside a rootless container are owned by the host's root user and hence cannot be read inside the container's user namespace.
    54  
    55  Further note that `podman cp` does not support globbing (e.g., `cp dir/*.txt`).  If you want to copy multiple files from the host to the container you may use xargs(1) or find(1) (or similar tools for chaining commands) in conjunction with `podman cp`.  If you want to copy multiple files from the container to the host, you may use `podman mount CONTAINER` and operate on the returned mount point instead (see ALTERNATIVES below).
    56  
    57  ## OPTIONS
    58  
    59  #### **--archive**, **-a**
    60  
    61  Archive mode (copy all uid/gid information).
    62  When set to true, files copied to a container will have changed ownership to the primary UID/GID of the container.
    63  When set to false, maintain uid/gid from archive sources instead of changing them to the primary uid/gid of the destination container.
    64  The default is **true**.
    65  
    66  ## ALTERNATIVES
    67  
    68  Podman has much stronger capabilities than just `podman cp` to achieve copying files between the host and containers.
    69  
    70  Using standard **[podman-mount(1)](podman-mount.1.md)** and **[podman-unmount(1)](podman-unmount.1.md)** takes advantage of the entire linux tool chain, rather than just cp.
    71  
    72  copying contents out of a container or into a container, can be achieved with a few simple commands. For example:
    73  
    74  To copy the `/etc/foobar` directory out of a container and onto `/tmp` on the host, the following commands can be executed:
    75  
    76  	mnt=$(podman mount CONTAINERID)
    77  	cp -R ${mnt}/etc/foobar /tmp
    78  	podman umount CONTAINERID
    79  
    80  To untar a tar ball into a container, following commands can be executed:
    81  
    82  	mnt=$(podman mount CONTAINERID)
    83  	tar xf content.tgz -C ${mnt}
    84  	podman umount CONTAINERID
    85  
    86  To install a package into a container that
    87  does not have dnf installed, following commands can be executed:
    88  
    89  	mnt=$(podman mount CONTAINERID)
    90  	dnf install --installroot=${mnt} httpd
    91  	chroot ${mnt} rm -rf /var/log/dnf /var/cache/dnf
    92  	podman umount CONTAINERID
    93  
    94  By using `podman mount` and `podman unmount`, one can use all of the
    95  standard linux tools for moving files into and out of containers, not just
    96  the cp command.
    97  
    98  ## EXAMPLES
    99  
   100  - Copy a file from host to a container.
   101    ```
   102    podman cp /myapp/app.conf containerID:/myapp/app.conf
   103    ```
   104  
   105  - Copy a file from a container to a directory on another container.
   106    ```
   107    podman cp containerID1:/myfile.txt containerID2:/tmp
   108    ```
   109  
   110  - Copy a directory on a container to a directory on the host.
   111    ```
   112    podman cp containerID:/myapp/ /myapp/
   113    ```
   114  
   115  - Copy the contents of a directory on a container to a directory on the host.
   116    ```
   117    podman cp containerID:/home/myuser/. /home/myuser/
   118    ```
   119  
   120  - Copy a directory on a container into a directory on another.
   121    ```
   122    podman cp containerA:/myapp containerB:/yourapp
   123    ```
   124  
   125  - Stream a tar archive from `STDIN` to a container.
   126    ```
   127    podman cp - containerID:/myfiles.tar.gz < myfiles.tar.gz
   128    ```
   129  
   130  ## SEE ALSO
   131  **[podman(1)](podman.1.md)**, **[podman-mount(1)](podman-mount.1.md)**, **[podman-unmount(1)](podman-unmount.1.md)**