Minimal static web image
FROM nginx:alpine
COPY index.html /usr/share/nginx/html/index.html
EXPOSE 80- FROM chooses the base image.
- COPY adds your page to the image.
- EXPOSE documents the intended container port but does not publish it to the host.
Write a clear Dockerfile, understand build context and common instructions, and build your first custom application image.
Docker reads Dockerfile instructions and sends a build context containing files available to COPY/ADD. FROM selects a base stage. RUN executes commands while building. COPY places files from the build context into the image.
CMD and ENTRYPOINT influence the process that starts when a container is run; they are not commands that execute during docker build.
The final argument to docker build is the build context, often a directory such as dot. Files outside that context cannot normally be copied by ordinary Dockerfile COPY instructions. Sending an unnecessarily large context slows builds and can accidentally expose files to the builder.
A good image has a clear purpose and a predictable foreground process. Containers should not rely on interactive login shells to start the application. Use image metadata and runtime flags for configuration that changes between environments.
FROM nginx:alpine
COPY index.html /usr/share/nginx/html/index.html
EXPOSE 80docker build -t gnu-docker-web:1.0 .
docker run --rm -p 8080:80 gnu-docker-web:1.0Goal: Create a static website image and run it without bind-mounting the source file.
mkdir -p ~/docker-fundamentals/web && cd ~/docker-fundamentals/web
printf '<h1>GNU Group Docker Lab</h1>\n' > index.htmlcat > Dockerfile <<'EOF'
FROM nginx:alpine
COPY index.html /usr/share/nginx/html/index.html
EXPOSE 80
EOFdocker build -t gnu-docker-web:1.0 .docker run -d --name gnu-web -p 8080:80 gnu-docker-web:1.0
curl http://127.0.0.1:8080/docker rm -f gnu-webProduction release pipelines build versioned images once and promote those artifacts between environments rather than editing files inside running containers.
Open each answer only after you have tried to answer the question yourself.
During image build.
It selects the current directory as the build context.
No. Host publishing is normally done with runtime options such as -p or Compose ports.