1podman-cp(1) General Commands Manual podman-cp(1)
2
3
4
6 podman-cp - Copy files/folders between a container and the local
7 filesystem
8
9
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
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
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
120 --overwrite
121 Allow directories to be overwritten with non-directories and vice
122 versa. By default, podman cp errors out when attempting to overwrite,
123 for instance, a regular file with a directory. Use this option, if you
124 want to allow this behavior.
125
126
128 Podman has much stronger capabilities than just podman cp to achieve
129 copying files between the host and containers.
130
131
132 Using standard podman-mount(1) and podman-unmount(1) takes advantage of
133 the entire linux tool chain, rather than just cp.
134
135
136 copying contents out of a container or into a container, can be
137 achieved with a few simple commands. For example:
138
139
140 To copy the /etc/foobar directory out of a container and onto /tmp on
141 the host, the following commands can be executed:
142
143
144 mnt=$(podman mount CONTAINERID)
145 cp -R ${mnt}/etc/foobar /tmp
146 podman umount CONTAINERID
147
148
149
150 To untar a tar ball into a container, following commands can be exe‐
151 cuted:
152
153
154 mnt=$(podman mount CONTAINERID)
155 tar xf content.tgz -C ${mnt}
156 podman umount CONTAINERID
157
158
159
160 To install a package into a container that does not have dnf installed,
161 following commands can be executed:
162
163
164 mnt=$(podman mount CONTAINERID)
165 dnf install --installroot=${mnt} httpd
166 chroot ${mnt} rm -rf /var/log/dnf /var/cache/dnf
167 podman umount CONTAINERID
168
169
170
171 By using podman mount and podman unmount, one can use all of the stan‐
172 dard linux tools for moving files into and out of containers, not just
173 the cp command.
174
175
177 • Copy a file from host to a container.
178
179 podman cp /myapp/app.conf containerID:/myapp/app.conf
180
181
182
183 • Copy a file from a container to a directory on another con‐
184 tainer.
185
186 podman cp containerID1:/myfile.txt containerID2:/tmp
187
188
189
190 • Copy a directory on a container to a directory on the host.
191
192 podman cp containerID:/myapp/ /myapp/
193
194
195
196 • Copy the contents of a directory on a container to a directory
197 on the host.
198
199 podman cp containerID:/home/myuser/. /home/myuser/
200
201
202
203 • Copy a directory on a container into a directory on another.
204
205 podman cp containerA:/myapp containerB:/yourapp
206
207
208
209 • Stream a tar archive from STDIN to a container.
210
211 podman cp - containerID:/myfiles.tar.gz < myfiles.tar.gz
212
213
214
215
216
218 podman(1), podman-mount(1), podman-unmount(1)
219
220
221
222 podman-cp(1)