gvgramazio
gvgramazio

Reputation: 1154

What is the proper way of add the content of the directory where the dockerfile is?

I know that usually, one adds a directory with COPY or ADD. What if I want to add the contents of the directory where the dockerfile is (including the dockerfile itself) in the image?

Upvotes: 1

Views: 38

Answers (1)

BMitch
BMitch

Reputation: 263627

You can add . for the current directory:

COPY . /build-context/

That would copy your build context to the image into a destination directory called /build-context. I call it build context rather than your current directory because that's the source of a COPY command. Docker is client/server based, so the client where you are running the docker command from may be different than the server where the build is performed. You see this when you run a docker build, there's an initial packaging of the build context and then sending that to the potentially remote build server. You control the build context with the last arg to the build command:

docker build -t your_image .

The . at the end of the build command sends the current directory to the backend as the context. But this could be a different directory, or even a remote git repo, so make sure this is set as desired before attempting the above COPY command.

Upvotes: 3

Related Questions