Guide Docker Beginner

Build a Custom Image

Package a static page, rebuild it, and compare versions.

1 min read

Objective

Produce two image versions and explain why rebuilding does not update an existing container.

Create the Files

In an empty directory, create index.html:

<h1>Docker lab version 1</h1>

Create Dockerfile:

FROM nginx:alpine
COPY index.html /usr/share/nginx/html/index.html

Create .dockerignore:

.git
.env
*.log

Build and Verify

docker build -t docker-lab-site:1 .
docker run -d --name docker-lab-site-v1 -p 127.0.0.1:8091:80 docker-lab-site:1

Open http://localhost:8091. Change the HTML heading to version 2, then:

docker build -t docker-lab-site:2 .
docker run -d --name docker-lab-site-v2 -p 127.0.0.1:8092:80 docker-lab-site:2

Port 8091 should still show version 1; port 8092 should show version 2.

Cleanup

docker stop docker-lab-site-v1 docker-lab-site-v2
docker rm docker-lab-site-v1 docker-lab-site-v2

Interview Angle

Explain the relationship between source files, built images, and running containers.

Next: Persistent data.


Docker Roadmap

Add More Questions to This Guide

Know a question that should be here? Share it and help the community!

Open Google Form