Compare commits
No commits in common. "cd0dd94d4cc2c9179b73e7455910595ddd9d1662" and "21e66d9792552354066782e78942c1dbc347d9c3" have entirely different histories.
cd0dd94d4c
...
21e66d9792
4 changed files with 1 additions and 95 deletions
|
|
@ -1,7 +1,5 @@
|
||||||
services:
|
services:
|
||||||
nginx:
|
nginx:
|
||||||
build:
|
build: ./
|
||||||
context: ./
|
|
||||||
dockerfile: Containerfile
|
|
||||||
ports:
|
ports:
|
||||||
- "80:80"
|
- "80:80"
|
||||||
|
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
FROM debian:12
|
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y curl
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY hello.sh .
|
|
||||||
RUN chmod +x hello.sh
|
|
||||||
|
|
||||||
ENV NAME=Trainee
|
|
||||||
|
|
||||||
CMD ["./hello.sh"]
|
|
||||||
|
|
@ -1,75 +0,0 @@
|
||||||
# Exercise 12a — Build a Containerfile step by step
|
|
||||||
#
|
|
||||||
# Start with an empty Containerfile and add one instruction at a time.
|
|
||||||
# After each step: podman build -t myapp:latest .
|
|
||||||
# Then inspect the result before moving on.
|
|
||||||
|
|
||||||
cd listings/exercises/ex12a-containerfile-steps/
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------
|
|
||||||
# Step 1 — Base image
|
|
||||||
# -----------------------------------------------------------------------
|
|
||||||
# Containerfile:
|
|
||||||
# FROM debian:12
|
|
||||||
|
|
||||||
podman build -t myapp:latest .
|
|
||||||
podman images myapp:latest # ~121 MB
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------
|
|
||||||
# Step 2 — Install software (creates a new layer)
|
|
||||||
# -----------------------------------------------------------------------
|
|
||||||
# Add to Containerfile:
|
|
||||||
# RUN apt-get update && apt-get install -y curl
|
|
||||||
|
|
||||||
podman build -t myapp:latest .
|
|
||||||
podman images myapp:latest # ~159 MB — layer is visible
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------
|
|
||||||
# Step 3 — Working directory
|
|
||||||
# -----------------------------------------------------------------------
|
|
||||||
# Add to Containerfile:
|
|
||||||
# WORKDIR /app
|
|
||||||
|
|
||||||
podman build -t myapp:latest .
|
|
||||||
podman run --rm myapp:latest pwd # prints /app
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------
|
|
||||||
# Step 4 — Copy your script into the image
|
|
||||||
# -----------------------------------------------------------------------
|
|
||||||
# Add to Containerfile:
|
|
||||||
# COPY hello.sh .
|
|
||||||
# RUN chmod +x hello.sh
|
|
||||||
|
|
||||||
podman build -t myapp:latest .
|
|
||||||
podman run --rm myapp:latest ls -la # hello.sh is there
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------
|
|
||||||
# Step 5 — Environment variable
|
|
||||||
# -----------------------------------------------------------------------
|
|
||||||
# Add to Containerfile:
|
|
||||||
# ENV NAME=Trainee
|
|
||||||
|
|
||||||
podman build -t myapp:latest .
|
|
||||||
podman run --rm myapp:latest env | grep NAME
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------
|
|
||||||
# Step 6 — Start command
|
|
||||||
# -----------------------------------------------------------------------
|
|
||||||
# Add to Containerfile:
|
|
||||||
# CMD ["./hello.sh"]
|
|
||||||
|
|
||||||
podman build -t myapp:latest .
|
|
||||||
podman run --rm myapp:latest # uses ENV NAME=Trainee
|
|
||||||
podman run --rm -e NAME=Frank myapp:latest # override at runtime
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------
|
|
||||||
# Bonus: layers — chained vs. separate RUN
|
|
||||||
# -----------------------------------------------------------------------
|
|
||||||
# Two separate RUN = two layers:
|
|
||||||
# RUN apt-get update
|
|
||||||
# RUN apt-get install -y curl
|
|
||||||
#
|
|
||||||
# One chained RUN = one layer:
|
|
||||||
# RUN apt-get update && apt-get install -y curl
|
|
||||||
|
|
||||||
podman inspect myapp:latest --format '{{len .RootFS.Layers}} layers'
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
echo "Hello, ${NAME:-World}!"
|
|
||||||
echo "Hostname: $(hostname)"
|
|
||||||
echo "Date: $(date)"
|
|
||||||
curl --version | head -1
|
|
||||||
Loading…
Add table
Reference in a new issue