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 [container:]src_path [container:]dest_path
12
13
15 Copies the contents of src_path to the dest_path. You can copy from the
16 containers's filesystem to the local machine or the reverse, from the
17 local filesystem to the container. If - is specified for either the
18 SRC_PATH or DEST_PATH, you can also stream a tar archive from STDIN or
19 to STDOUT.
20
21
22 The CONTAINER can be a running or stopped container. The src_path or
23 dest_path can be a file or directory.
24
25
26 The podman cp command assumes container paths are relative to the
27 container's / (root) directory.
28
29
30 This means supplying the initial forward slash is optional;
31
32
33 The command sees compassionate_darwin:/tmp/foo/myfile.txt and
34 compassionate_darwin:tmp/foo/myfile.txt as 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
49 - dest_path does not exist and ends with /
50 - dest_path is created as a directory and the file is copied into
51 this directory using the basename from src_path
52 - dest_path exists and is a file
53 - the destination is overwritten with the source file's contents
54 - dest_path exists and is a directory
55 - the file is copied into this directory using the basename from
56 src_path
57
58
59 src_path specifies a directory
60 - dest_path does not exist
61 - dest_path is created as a directory and the contents of the
62 source directory are copied into this directory
63 - dest_path exists and is a file
64 - Error condition: cannot copy a directory to a file
65 - dest_path exists and is a directory
66 - src_path ends with /
67 - the source directory is copied into this directory
68 - src_path ends with /. (that is: slash followed by dot)
69 - the content of the source directory is copied into this
70 directory
71
72
73 The command requires src_path and dest_path to exist according to the
74 above rules.
75
76
77 If src_path is local and is a symbolic link, the symbolic target, is
78 copied by default.
79
80
81 A colon (:) is used as a delimiter between CONTAINER and its path.
82
83
84 You can also use : when specifying paths to a src_path or dest_path on
85 a local machine, for example, file:name.txt.
86
87
88 If you use a : in a local machine path, you must be explicit with a
89 relative or absolute path, for example:
90 /path/to/file:name.txt or ./file:name.txt
91
92
94 --extract
95
96
97 Extract the tar file into the destination directory. If the destination
98 directory is not provided, extract the tar file into the root
99 directory.
100
101
102 --pause
103
104
105 Pause the container while copying into it to avoid potential security
106 issues around symlinks. Defaults to true.
107
108
110 Podman has much stronger capabilities than just podman cp to achieve
111 copy files between host and container.
112
113
114 Using standard podman-mount and podman-umount takes advantage of the
115 entire linux tool chain, rather then just cp.
116
117
118 If a user wants to copy contents out of a container or into a
119 container, they can execute a few simple commands.
120
121
122 You can copy from the container's file system to the local machine or
123 the reverse, from the local filesystem to the container.
124
125
126 If you want to copy the /etc/foobar directory out of a container and
127 onto /tmp on the host, you could execute the following commands:
128
129
130 mnt=$(podman mount CONTAINERID)
131 cp -R ${mnt}/etc/foobar /tmp
132 podman umount CONTAINERID
133
134
135
136 If you want to untar a tar ball into a container, you can execute these
137 commands:
138
139
140 mnt=$(podman mount CONTAINERID)
141 tar xf content.tgz -C ${mnt}
142 podman umount CONTAINERID
143
144
145
146 One last example, if you want to install a package into a container
147 that does not have dnf installed, you could execute something like:
148
149
150 mnt=$(podman mount CONTAINERID)
151 dnf install --installroot=${mnt} httpd
152 chroot ${mnt} rm -rf /var/log/dnf /var/cache/dnf
153 podman umount CONTAINERID
154
155
156
157 This shows that using podman mount and podman umount you can use all of
158 the standard linux tools for moving files into and out of containers,
159 not just the cp command.
160
161
163 podman cp /myapp/app.conf containerID:/myapp/app.conf
164
165
166 podman cp /home/myuser/myfiles.tar containerID:/tmp
167
168
169 podman cp containerID:/myapp/ /myapp/
170
171
172 podman cp containerID:/home/myuser/. /home/myuser/
173
174
175 podman cp --extract /home/myuser/myfiles.tar.gz containerID:/myfiles
176
177
178 podman cp - containerID:/myfiles.tar.gz < myfiles.tar.gz
179
180
182 podman(1), podman-mount(1), podman-umount(1)
183
184
185
186 podman-cp(1)