Menu
Coddy logo textTech

The COPY Instruction

Part of the Introduction to Docker section of Coddy's Terminal journey — lesson 25 of 40.

Most images need your own files baked in: source code, config, data. The COPY instruction copies a file from the build context (the directory you build from) into the image:

FROM alpine
COPY message.txt /message.txt

The format is COPY SOURCE DESTINATION. Here message.txt from your directory is copied to /message.txt inside the image.

The file genuinely lives in the image afterward, so a container built from it can read the file for real:

docker build -t hasfile .
docker run hasfile cat /message.txt
challenge icon

Challenge

Medium

A file named note.txt is already in your directory. Write a Dockerfile that is FROM alpine and copies note.txt to /note.txt in the image. Build it tagged noted, then run it to cat /note.txt.

Cheat sheet

Use COPY SOURCE DESTINATION to copy files from the build context into the image:

FROM alpine
COPY message.txt /message.txt

The file is baked into the image and available in any container run from it:

docker build -t hasfile .
docker run hasfile cat /message.txt

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Introduction to Docker