Thuta Learning
IntermediateDevOps & Toolsintermediate

Dockerfile Intro

Relax. We'll talk through this in plain words — no textbook voice.

Dockerfile is a text file that lays out, as instructions, which base image a Docker image starts from, which files get copied in, which commands get run, and what command runs when the container starts. The file name is written as Dockerfile with no extension.

dockerfile
# Create a file named Dockerfile
FROM nginx:alpine
WORKDIR /usr/share/nginx/html
COPY index.html .
EXPOSE 80

FROM sets the base image. WORKDIR picks the working folder inside the container. COPY copies your local index.html into the Nginx web root. EXPOSE documents that the container will use port 80.

You should see
Once you build and run this Dockerfile, you'll be able to see your index.html in the browser, served through Nginx.

Info

EXPOSE doesn't automatically give you access from the host computer. To reach it from a browser, you still need to map the port with docker run -p 8080:80.

Easy traps

  • If the Dockerfile and index.html aren't in the same folder, you may get a "file not found" error at COPY index.html .