Ad space (banner)
AD

Got the fundamentals? A structured Docker course is a fast way to level up.

Find Docker courses on Udemy

Affiliate link. Costs you nothing extra.

🐳Docker Lessons
Lesson 29 / 45

Adding Files with COPY

When you need your source code inside the image, use COPY. It copies files from the build context into the image.

The syntax is COPY source destination. The source is relative to the directory you run docker build from.

Writing COPY . /app copies everything from the current directory into /app in the image.

A common stumble is copying everything at once, including node_modules and .git, which bloats the image and slows builds. A .dockerignore file solves this.

In real work, dependency files are copied and installed before the source code, so that the expensive install layer stays cached when only your code changes.

Docker
Try it (type this into the pseudo terminal)
docker build -t myapp .

🧑‍💻 You can type this command into the Docker pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)