Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tilde Expansion Doesn't Work in Docker COPY Command

I have a Dockerfile with the following line:

COPY *.zip ~user1

The user user1 already exists and has a home directory (i.e. /home/user1). The goal, of course, is to copy the zip file into that user's home dir, however the result of the above is that the zip file is copied to a file named literally /~user1 in the image.

The following does work as expected:

COPY *.zip /home/user1

Is this a bug in Docker or is there a limitation related to tilde expansion that I'm not aware of?

Using Docker 1.13.0 on Mac.

like image 632
Dave L. Avatar asked Jan 29 '17 23:01

Dave L.


People also ask

What is the Copy command in docker?

This Docker copy (cp) command takes a file that exists inside a Docker container and saves it to your computer's local file system. The container-name specified in the example command can be either the name given to the Docker container when it was started, or the unique ID that Docker assigned to the container.

What is difference between docker add and copy command?

COPY is a docker file command that copies files from a local source location to a destination in the Docker container. ADD command is used to copy files/directories into a Docker image.


1 Answers

Tilde expansion for COPY is not supported.

From The COPY docs:

The dest is an absolute path, or a path relative to WORKDIR, into which the source will be copied inside the destination container.

Example:

COPY test relativeDir/   # adds "test" to `WORKDIR`/relativeDir/
COPY test /absoluteDir/  # adds "test" to /absoluteDir/
like image 174
Chris McKinnel Avatar answered Oct 07 '22 20:10

Chris McKinnel