A Dockerfile is like a recipe card 🍰.
It tells Docker how to build an image step by step.
Each line in a Dockerfile is an instruction, and Docker reads it from top to bottom to create the image.
👉 Fun fact: Dockerfile instructions are case-sensitive
FROM ✅ worksfrom ❌ does notBaking a cake 🧁
Dockerfile
FROM ubuntuRUN apt-get updateCOPY codeCMD run appSame idea — follow steps in order.
Defines the base image for your application.
FROM ubuntu:latest
FROM ubuntu:latestAdds information like version, maintainer, etc.
LABEL version="1.0"
LABEL version="1.0"Sets environment variables inside the image.
ENV owner="shan"
ENV owner="shan"Defines a mount point for data.
VOLUME ["/data"]
VOLUME ["/data"]Sets the default directory for commands.
WORKDIR /lak
WORKDIR /lakCopies files from host into the image.
COPY AStc /lak
COPY AStc /lakSimilar to COPY, but can unzip or download files.
ADD dumptar /lak
ADD dumptar /lakRuns commands while the image is being built.
RUN apt update && useradd -ms /bin/bash shan
RUN apt update && useradd -ms /bin/bash shanRuns container commands as a specific user.
USER shan
USER shanDocuments which port the container listens on.
EXPOSE 8080
EXPOSE 8080Defines the default command to run when container starts.
(Only one CMD is allowed.)
CMD ["ping", "8.8.8.8"]
CMD ["ping", "8.8.8.8"]Makes the container behave like a command.
ENTRYPOINT ["ping"]
ENTRYPOINT ["ping"]A container must have a foreground process to keep running.
👉 If there is no foreground process, the container stops immediately.
✅ Example:
Tags are version labels for images.
docker tag <container_id> username/app:v1
docker tag <container_id> username/app:v1👉 Think of it like:
Essay_v1.docxEssay_v2.docx📌 Fact:
If no tag is specified, Docker automatically uses latest.
Creates an image from the Dockerfile.
docker build -t username/app:1.0 .
docker build -t username/app:1.0 .Uploads the image to a registry.
docker push username/app:1.0
docker push username/app:1.0👉 Just like: