Estimated time: 60 minutes.
Package a web page into your own image and push it to a registry so that others can pull and run it.
The exercise starts from a one-line page (v1) → edit the content and rebuild (v2) → upgrade it to a complete landing page (v3) as the official deliverable.
Acceptance criteria: (1) the application directory has a Dockerfile and a .dockerignore, and docker build succeeds;
(2) docker history shows the layer you added sitting on top of the base image's layers; (3) you can run the image you just built and reach a page with your own content;
(4) write the sample landing page from Step 10 (a single HTML+CSS file, self-contained, with <meta charset="utf-8">; you may replace the text with your own content) and build it as v3,
and curl returns exactly that page; (5) docker push v3 together with the latest tag to Docker Hub (or Quay/GHCR) and someone else can pull and run it —
the public image path is the result of the exercise.
Before you start: the exercise works with both root and a regular user.
Step 1 determines your permission to call the Docker daemon and settles on one way of invoking it (with sudo or without) — keep it unchanged until the end, because docker login stores credentials per user.
This exercise works whether you are logged in as root or as a regular user, but you must know who you are BEFORE typing commands: a regular user cannot write to /opt and cannot call the Docker daemon unless they are in the docker group.
Pick one way of invoking Docker (with sudo or without) and keep it unchanged until the end.
whoami
id
docker version
# if you get permission denied — add the user to the docker group:
sudo usermod -aG docker "$USER"
newgrp docker
docker version
Notes: The error permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock means the user is not allowed to call the daemon:
add the user to the docker group and log in again (newgrp docker applies immediately to the current shell), or put sudo in front of every docker command.
Mixing the two ways will break at the push step — see the note in Step 2.
Create accounts on Docker Hub and Quay.io. Log in with an access token, not your account password.
Log in using exactly the way of invoking Docker you chose in Step 1, then verify that you are logged in to the right account.
docker login
docker login quay.io
docker info | grep -i username
ls -l "$HOME/.docker/config.json"
Notes: An access token can be revoked individually without changing your password, and must never be committed to source code (Docker: access tokens).
A common trap for regular users: docker login stores credentials in $HOME/.docker/config.json of the user running the command — sudo docker login stores them in /root/.docker/config.json.
Logging in with sudo and then pushing without sudo (or the other way around) will report denied even though the account is perfectly valid.
Create a dedicated directory and put the web content files in it. This directory will be the build context, so it should contain only what really needs to be packaged.
Use a directory under $HOME so that any user can write to it.
mkdir -p ~/inet-web && cd ~/inet-web
echo "<h1>Student's image — put your own name here</h1>" > index.html
ls -la
pwd
du -sh .
Notes: Change the content of index.html to the name of whoever is doing the exercise — that is how you tell the images apart when submitting (Docker: build context).
If you want to place it at /opt/inet-web following the system convention, you must grant permissions first: sudo mkdir -p /opt/inet-web && sudo chown "$USER":"$USER" /opt/inet-web — otherwise a regular user gets Permission denied right at mkdir.
Never create files with sudo and then build as a regular user: the files belong to root, the COPY step still runs, but the command that edits the content in Step 9 will be denied.
The file name is fixed: Dockerfile. Four instructions are enough for this exercise: choose a base, attach descriptive labels, copy the content, declare the port.
cat > Dockerfile <<'EOF'
FROM nginx:1.27-alpine
LABEL maintainer="student"
LABEL description="Static web page packaged with a Dockerfile"
COPY index.html /usr/share/nginx/html/index.html
EXPOSE 80
EOF
cat Dockerfile
Notes: EXPOSE only declares the port in the image metadata; to reach it from outside you still need -p when running the container (Dockerfile reference).
Write .dockerignore first because the entire build context is sent to the build process, and this image is about to be pushed to a public registry.
cat > .dockerignore <<'EOF'
.git
.env
*.key
*.pem
node_modules
dist
EOF
cat .dockerignore
Notes: A secret that ends up in a pushed image is a data-exposure incident — removing it from the image afterwards is not enough;
you must revoke and reissue that secret (Docker:.dockerignore).
When building, pay attention to the dot at the end of the command: it is the build context, not punctuation. List the images before and after to see the difference.
docker image ls | grep inet-web
docker build -t inet-web:v1 .
docker image ls | grep inet-web
Notes: If the build stops at the COPY step, you are most likely in the wrong directory (docker build).
Read the layers and metadata to make sure the image contains exactly the content you just packaged, rather than reusing an old cached layer.
docker image history inet-web:v1
docker image inspect --format "{{.Config.Labels}}" inet-web:v1
docker image inspect --format "{{.Config.ExposedPorts}}" inet-web:v1
docker image inspect --format "{{.Os}} {{.Architecture}} {{.Size}}" inet-web:v1
Notes: The top layer is the part you just added; below it are the layers of the base image (docker image history).
Run the image, then verify with a browser or curl. The content must be your own page, not the base image's default page.
docker run -d --name inet-web -p 8080:80 inet-web:v1
docker ps
curl -s http://localhost:8080
docker logs inet-web
Notes: The build log is in the output of the build command; docker logs only shows the log from when the container runs — two different sources.
This step practices the right way to make lasting changes: edit the source and build a new tag, instead of hot-editing a running container.
echo "<h1>Version 2 — self-built</h1>" > index.html
docker build -t inet-web:v2 .
docker run -d --name inet-web-v2 -p 8081:80 inet-web:v2
curl -s http://localhost:8081
Notes: The two ports return two different contents — each tag is an independent, traceable version.
Replace the one-line page with a real HTML+CSS page that is self-contained (no external CDN/font/image calls) and has <meta charset="utf-8">.
The command below writes a sample landing page; you may change the text to your own content as long as you keep the meta charset line. This is the official deliverable of the exercise.
cat > index.html <<'EOF'
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>inet-web · A self-packaged image</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body { margin: 0; font-family: system-ui, sans-serif; background: #0f172a; color: #e2e8f0; }
header { padding: 64px 24px; text-align: center; background: linear-gradient(135deg, #1e3a8a, #0f766e); }
h1 { margin: 0 0 12px; font-size: 2.2rem; }
main { max-width: 760px; margin: 0 auto; padding: 32px 24px; display: grid; gap: 16px; }
.card { background: #1e293b; border-radius: 12px; padding: 20px; }
.card h2 { margin: 0 0 8px; font-size: 1.1rem; color: #5eead4; }
footer { text-align: center; padding: 24px; color: #94a3b8; font-size: .9rem; }
</style>
<header>
<h1>inet-web — a landing page inside a Docker image</h1>
<p>One HTML+CSS file, no external CDN, fonts or images.</p>
</header>
<main>
<section class="card"><h2>Build once</h2><p>The content lives in the layer the Dockerfile adds on top of the nginx image.</p></section>
<section class="card"><h2>Run anywhere</h2><p>Anyone who pulls the image sees exactly this page, with no outside network needed.</p></section>
<section class="card"><h2>Versioned</h2><p>v1, v2, v3 are three independent tags; latest is just a conventional label.</p></section>
</main>
<footer>Version v3</footer>
</html>
EOF
docker build -t inet-web:v3 .
docker run -d --name inet-web-v3 -p 8083:80 inet-web:v3
curl -s http://localhost:8083 | head -5
Notes: A page with non-ASCII text (accented letters, the “—” character) must declare <meta charset="utf-8">; without it, the browser reads the page as Latin-1 and shows mojibake (the — character turns into “—”).
Keep the image self-contained so it does not depend on the viewer's network (Dockerfile reference).
Push the official deliverable v3 together with the latest tag.
Replace <account> with the registry account name of whoever is doing the exercise — this is the name on Docker Hub/Quay, not the Linux username you are logged in with on the machine.
Push using exactly the same way of invoking Docker that you used for docker login in Step 2.
docker tag inet-web:v3 docker.io/<account>/inet-web:v3
docker tag inet-web:v3 docker.io/<account>/inet-web:latest
docker push docker.io/<account>/inet-web:v3
docker push docker.io/<account>/inet-web:latest
Notes: latest is only a conventional label — it does NOT automatically point to the newest tag; you must re-tag it on every release.
The error denied:requested access to the resource is denied has three causes, to be checked in this order: (1) the tag does not match the target account/repository;
(2) you have not run docker login; (3) login and push were done as different users —
for example sudo docker login (which stores the credentials in /root/.docker/config.json) followed by docker push as a regular user, or the other way around.
Cross-check quickly with docker info | grep -i username, run in exactly the way you are about to push (docker tag,
Delete the local copies, pull again using the latest tag, then run it. Record the public image path so that others can verify it.
docker rm -f inet-web-v3
docker rmi docker.io/<account>/inet-web:v3 docker.io/<account>/inet-web:latest inet-web:v3
docker pull docker.io/<account>/inet-web:latest
docker run -d --name inet-web-pull -p 8082:80 docker.io/<account>/inet-web:latest
curl -s http://localhost:8082 | head -5
Notes: Pulling from another machine must also return exactly that page.
If the pipeline reports toomanyrequests, log in with an account that has its own rate limit instead of pulling anonymously (Docker Hub: usage limits).
This is the error you hit at the very first docker command when logged in as a non-root account.
whoami
docker version
Result:
hocvien
Client: Docker Engine - Community
Version: 27.3.1
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.47/version": dial unix /var/run/docker.sock: connect: permission denied
Notes: The Client section still appears because the binary runs; only the connection to the daemon is refused.
Fix: sudo usermod -aG docker "$USER" then newgrp docker (or log in again) — or put sudo in front of every docker command and keep doing so until the end of the exercise.
This is why the exercise uses a directory under $HOME.
mkdir -p /opt/inet-web
mkdir -p ~/inet-web && cd ~/inet-web && pwd
Result:
mkdir: cannot create directory ‘/opt/inet-web’: Permission denied
/home/hocvien/inet-web
Notes: If you want to keep /opt: sudo mkdir -p /opt/inet-web && sudo chown "$USER":"$USER" /opt/inet-web. Granting ownership means later steps that edit index.html do not need sudo.
The Dockerfile has only four instructions, enough to package a static page.
cat Dockerfile
Result:
FROM nginx:1.27-alpine
LABEL maintainer="student"
LABEL description="Static web page packaged with a Dockerfile"
COPY index.html /usr/share/nginx/html/index.html
EXPOSE 80
Notes: The file name is fixed: Dockerfile; if you use a different name you must pass -f when building.
The output of docker build numbers the steps that need to be executed.
docker build -t inet-web:v1 .
Result:
[+] Building 3.2s (7/7) FINISHED
=> [internal] load build definition from Dockerfile
=> [internal] load .dockerignore
=> [internal] load metadata for docker.io/library/nginx:1.27-alpine
=> [1/2] FROM docker.io/library/nginx:1.27-alpine
=> [internal] load build context
=> [2/2] COPY index.html /usr/share/nginx/html/index.html
=> exporting to image
=> => naming to docker.io/library/inet-web:v1
Notes: The two numbered steps [1/2] and [2/2] correspond to FROM and COPY; the rest are the configuration-loading and image-export steps.
The image history clearly shows the layer you just added sitting on top of the base image's layers.
docker image history inet-web:v1
Result:
IMAGE CREATED CREATED BY SIZE
b7f2c91a4d3e 2 minutes ago COPY index.html /usr/share/nginx/html/index... 61B
<missing> 3 weeks ago CMD ["nginx" "-g" "daemon off;"] 0B
<missing> 3 weeks ago EXPOSE map[80/tcp:{}] 0B
<missing> 3 weeks ago /bin/sh -c #(nop) ADD file:... in / 8.4MB
Notes: The top line is what the exercise added; the lines below come from the base image.
The page returned is exactly the file baked into the image.
docker run -d --name inet-web -p 8080:80 inet-web:v1
curl -s http://localhost:8080
Result:
<h1>Student's image — put your own name here</h1>
Notes: It differs from the base image's default page — proof that the content is inside the image, not mounted from the host.
Push the official deliverable together with the latest tag.
docker tag inet-web:v3 docker.io/<account>/inet-web:v3
docker tag inet-web:v3 docker.io/<account>/inet-web:latest
docker push docker.io/<account>/inet-web:v3
docker push docker.io/<account>/inet-web:latest
Result:
The push refers to repository [docker.io/<account>/inet-web]
5f70bf18a086: Pushed
a3c8dbb1e4f7: Mounted from library/nginx
v3: digest: sha256:5aead2... size: 856
latest: digest: sha256:5aead2... size: 856
Notes: v3 and latest have the same digest — they point to the same image. Layers already present on the registry show Mounted from; only the new layer is actually uploaded.
The most common error is a tag that does not match the target account/repository, or not being logged in.
docker push docker.io/wrong-account/inet-web:v3
Result:
denied: requested access to the resource is denied
Notes: Re-tag it correctly as <registry>/<account>/<repo>:<tag>, then docker login and push again.
When you log in with sudo but push as a regular user, the two commands read two different credential files.
sudo docker login
docker push docker.io/<account>/inet-web:v3
docker info | grep -i username
sudo docker info | grep -i username
Result:
Login Succeeded
denied: requested access to the resource is denied
Username: <account>
Notes: The Username line appears only for the command run with sudo — the credentials are in /root/.docker/config.json, while the regular user reads $HOME/.docker/config.json, which is still empty.
Log in again as the user who is about to push, or consistently use sudo for both login and push.
Delete the local copies, pull again with latest, and run the landing page.
docker rmi docker.io/<account>/inet-web:v3 docker.io/<account>/inet-web:latest inet-web:v3
docker pull docker.io/<account>/inet-web:latest
docker run -d --name inet-web-pull -p 8082:80 docker.io/<account>/inet-web:latest
curl -s http://localhost:8082 | head -6
Result:
latest: Pulling from <account>/inet-web
Status: Downloaded newer image for <account>/inet-web:latest
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>inet-web · A self-packaged image</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
Notes: The complete landing page lives independently of the build machine — this is the result of the exercise, together with the public image path (the latest or v3 tag).