I am using Docker on a Mac.
I have the following line on my Docker file.
COPY ~/.pip/pip.conf /root/.pip/pip.conf
this generates an error
ERROR [5/6] COPY ~/.pip/pip.conf /root/.pip/pip.conf 0.0s
------
> [5/6] COPY ~/.pip/pip.conf /root/.pip/pip.conf:
------
failed to compute cache key: “/~/.pip/pip.conf” not found: not found
what is the correct syntax to accomplish the above copy command?
3
Answers
There is none.
Also, you can’t COPY from outside of build context.
Copy the files to the build context before building the container and then COPY them from build context into the container.
When you build a docker image, COPY statements can only copy files from inside the ‘build context’. Usually the context is the directory containing the Dockerfile. The context is the directory and all directories below it. For security reasons, you’re not allowed to copy files from outside the build context.
Because of this, it only makes sense to copy files that you reference with regard to their location within the build context. It doesn’t really make sense to reference them relative to the user’s home directory, even if that directory is inside the build context.
You can’t access an arbitrary directory with
COPY
; the source is relative to the context. If you want to add your personalpip.conf
file to the Docker image, you need to copy it to the context before runningdocker build
.With the directive
use something like