Menu
Coddy logo textTech

What Is A Dockerfile

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

So far you have used images other people built. To build your own, you write a Dockerfile: a plain text file listing the steps to assemble an image, one instruction per line.

The most important instruction is FROM, which every Dockerfile starts with. It picks the base image you build on top of:

FROM alpine

This says to start from the alpine image. You then add more instructions below it to customize the image.

You can create the Dockerfile right from the terminal. One easy way is to write the lines into a file named Dockerfile:

cat > Dockerfile << 'EOF'
FROM alpine
EOF

Everything between EOF and EOF is written into the file.

challenge icon

Challenge

Beginner

Create a Dockerfile whose only line is FROM alpine, then print the file with cat to confirm its contents.

Cheat sheet

A Dockerfile is a plain text file with instructions to build a Docker image. Every Dockerfile starts with FROM to specify the base image:

FROM alpine

Create a Dockerfile from the terminal using a heredoc:

cat > Dockerfile << 'EOF'
FROM alpine
EOF

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