Rutnet
Rutnet

Reputation: 1673

Docker accessing path outside build context for COPY

If my project is structured:

docker:
  ==> Dockerfile_1
source_code

In Dockerfile1 I have:

COPY //source_code

How can I add the source_code folder to my dockerfile. I keep getting a message saying that:

COPY failed: Forbidden path outside the build context: ../source_code ()

Upvotes: 0

Views: 187

Answers (1)

Leonardo Dagnino
Leonardo Dagnino

Reputation: 3215

You cannot use paths outside the build context - this is done intentionally such that your container should be fully specified by the files in that directory.

What you usually want to do is simply have the Dockerfile live with the source code - there's rarely a reason to need it far from it.

Another possibility is being in the directory of your source code and using docker build -f /path/to/Dockerfile. This would be quite bothersome to use, and in my opinion, I can't see any way this would be justifiable over just placing the Dockerfile in your project root.

Upvotes: 1

Related Questions