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 alpineThis 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
EOFEverything between EOF and EOF is written into the file.
Challenge
BeginnerCreate 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 alpineCreate a Dockerfile from the terminal using a heredoc:
cat > Dockerfile << 'EOF'
FROM alpine
EOFTry it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.