1podman-cp(1)()                                                  podman-cp(1)()
2
3
4

NAME

6       podman-cp  -  Copy  files/folders  between  a  container  and the local
7       filesystem
8
9

SYNOPSIS

11       podman cp [options] [container:]src_path [container:]dest_path
12
13
14       podman    container    cp    [options]    [container:]src_path    [con‐
15       tainer:]dest_path
16
17

DESCRIPTION

19       podman  cp  allows  copying  the contents of src_path to the dest_path.
20       Files can be copied from a container to  the  local  machine  and  vice
21       versa  or  between  two  containers.   If - is specified for either the
22       SRC_PATH or DEST_PATH, one can also stream a tar archive from STDIN  or
23       to STDOUT.
24
25
26       The  containers  can  be  either running or stopped and the src_path or
27       dest_path can be a file or directory.
28
29
30       *IMPORTANT: The podman cp command assumes container paths are  relative
31       to  the  container's root directory (/), which means supplying the ini‐
32       tial forward slash is optional and  therefore  sees  compassionate_dar‐
33       win:/tmp/foo/myfile.txt  and compassionate_darwin:tmp/foo/myfile.txt as
34       identical.*
35
36
37       Local machine paths can be an absolute or relative value.  The  command
38       interprets  a local machine's relative paths as relative to the current
39       working directory where podman cp is run.
40
41
42       Assuming a path separator of /, a first argument of src_path and second
43       argument of dest_path, the behavior is as follows:
44
45
46       src_path specifies a file:
47         - dest_path does not exist
48           -  the file is saved to a file created at dest_path (note that par‐
49       ent directory must exist).
50         - dest_path exists and is a file
51           - the destination is overwritten with the source file's contents.
52         - dest_path exists and is a directory
53           - the file is copied into this directory using the base  name  from
54       src_path.
55
56
57       src_path specifies a directory:
58         - dest_path does not exist
59           -  dest_path  is  created  as  a  directory and the contents of the
60       source directory are copied into this directory.
61         - dest_path exists and is a file
62           - Error condition: cannot copy a directory to a file.
63         - dest_path exists and is a directory
64           - src_path ends with /
65             - the source directory is copied into this directory.
66           - src_path ends with /. (i.e., slash followed by dot)
67             - the content of the source directory is copied into this  direc‐
68       tory.
69
70
71       The  command  requires src_path and dest_path to exist according to the
72       above rules.
73
74
75       If src_path is local and is a symbolic link, the  symbolic  target,  is
76       copied by default.
77
78
79       A  colon ( : ) is used as a delimiter between a container and its path,
80       it can also be used when specifying paths to a src_path or dest_path on
81       a local machine, for example, file:name.txt.
82
83
84       *IMPORTANT: while using a colon ( : ) in a local machine path, one must
85       be  explicit  with  a  relative  or   absolute   path,   for   example:
86       /path/to/file:name.txt or ./file:name.txt*
87
88
89       Using - as the src_path streams the contents of STDIN as a tar archive.
90       The command extracts the content of the tar to  the  DEST_PATH  in  the
91       container. In this case, dest_path must specify a directory. Using - as
92       the dest_path streams the contents of the resource (can be a directory)
93       as a tar archive to STDOUT.
94
95
96       Note  that podman cp ignores permission errors when copying from a run‐
97       ning rootless container.  The TTY devices inside a  rootless  container
98       are  owned  by the host's root user and hence cannot be read inside the
99       container's user namespace.
100
101
102       Further note that  podman  cp  does  not  support  globbing  (e.g.,  cp
103       dir/*.txt).   If  you  want to copy multiple files from the host to the
104       container you may use xargs(1) or find(1) (or similar tools for  chain‐
105       ing  commands) in conjunction with podman cp.  If you want to copy mul‐
106       tiple files from the container to the host, you may  use  podman  mount
107       CONTAINER and operate on the returned mount point instead (see ALTERNA‐
108       TIVES below).
109
110

OPTIONS

112   --archive, -a
113       Archive mode (copy all uid/gid information).  When set to  true,  files
114       copied  to  a  container  will  have  changed  ownership to the primary
115       UID/GID of the container.  When set to false, maintain uid/gid from ar‐
116       chive  sources  instead  of changing them to the primary uid/gid of the
117       destination container.  The default is true.
118
119

ALTERNATIVES

121       Podman has much stronger capabilities than just podman  cp  to  achieve
122       copying files between the host and containers.
123
124
125       Using standard podman-mount(1) and podman-unmount(1) takes advantage of
126       the entire linux tool chain, rather than just cp.
127
128
129       copying contents out of  a  container  or  into  a  container,  can  be
130       achieved with a few simple commands. For example:
131
132
133       To  copy  the /etc/foobar directory out of a container and onto /tmp on
134       the host, the following commands can be executed:
135
136
137              mnt=$(podman mount CONTAINERID)
138              cp -R ${mnt}/etc/foobar /tmp
139              podman umount CONTAINERID
140
141
142
143       To untar a tar ball into a container, following commands  can  be  exe‐
144       cuted:
145
146
147              mnt=$(podman mount CONTAINERID)
148              tar xf content.tgz -C ${mnt}
149              podman umount CONTAINERID
150
151
152
153       To install a package into a container that does not have dnf installed,
154       following commands can be executed:
155
156
157              mnt=$(podman mount CONTAINERID)
158              dnf install --installroot=${mnt} httpd
159              chroot ${mnt} rm -rf /var/log/dnf /var/cache/dnf
160              podman umount CONTAINERID
161
162
163
164       By using podman mount and podman unmount, one can use all of the  stan‐
165       dard  linux tools for moving files into and out of containers, not just
166       the cp command.
167
168

EXAMPLES

170              • Copy a file from host to a container.
171
172                     podman cp /myapp/app.conf containerID:/myapp/app.conf
173
174
175
176              • Copy a file from a container to a directory  on  another  con‐
177                tainer.
178
179                     podman cp containerID1:/myfile.txt containerID2:/tmp
180
181
182
183              • Copy a directory on a container to a directory on the host.
184
185                     podman cp containerID:/myapp/ /myapp/
186
187
188
189              • Copy the contents of a directory on a container to a directory
190                on the host.
191
192                     podman cp containerID:/home/myuser/. /home/myuser/
193
194
195
196              • Copy a directory on a container into a directory on another.
197
198                     podman cp containerA:/myapp containerB:/yourapp
199
200
201
202              • Stream a tar archive from STDIN to a container.
203
204                     podman cp - containerID:/myfiles.tar.gz < myfiles.tar.gz
205
206
207
208
209

SEE ALSO

211       podman(1), podman-mount(1), podman-unmount(1)
212
213
214
215                                                                podman-cp(1)()
Impressum