Docker Essentials: Mastering Basic Commands and Dockerfile Components

🚢 Docker Basics: Commands and Dockerfile Components
📚 Introduction
As I continue my 12-day Docker learning series, today’s session was packed with hands-on experience!
In this blog, I’ll share:
Some essential Docker commands I practiced.
A theoretical overview of Dockerfile components — the blueprint for building Docker images.
If you are new to Docker or want a quick refresher, this will be a perfect guide.
🛠️ Basic Docker Commands You Must Know
Here are some of the fundamental Docker commands I learnt today:
Command | Purpose |
docker --version | Check the installed Docker version |
docker pull <image> | Download an image from Docker Hub |
docker images | List all downloaded images |
docker run <image> | Run a container from an image |
docker ps | List running containers |
docker ps -a | List all containers (running + stopped) |
docker stop <container_id> | Stop a running container |
docker rm <container_id> | Remove a stopped container |
docker rmi <image_id> | Remove a Docker image |
docker exec -it <container_id> bash | Access the shell inside a running container |
📌 Quick Tips:
Image: A snapshot/template used to create containers.
Container: A running instance of an image.
Always remove unused images/containers to free up space!
🏗️ Understanding Dockerfile Components
A Dockerfile is a text document that contains all the commands to assemble an image.
Here are the key components of a Dockerfile:
Instruction | Purpose |
FROM | Sets the base image for building the new image |
RUN | Executes commands inside the image during build time |
CMD | Provides default commands to run when a container is created |
LABEL | Adds metadata to the image (like version, description) |
EXPOSE | Informs Docker that the container listens on specific network ports |
ENV | Sets environment variables |
COPY | Copies files/folders from the local machine to the container |
ADD | Similar to COPY but can handle remote URLs and unpack archives |
WORKDIR | Sets the working directory inside the container |
ENTRYPOINT | Configures a container to run as an executable |
📈 Example: A Simple Dockerfile
dockerfileCopyEdit# Use an official Python runtime as a base image
FROM python:3.9-slim
# Set working directory
WORKDIR /app
# Copy current directory contents into the container at /app
COPY . /app
# Install any needed packages
RUN pip install --no-cache-dir -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Run app.py when the container launches
CMD ["python", "app.py"]
✨ Final Thoughts
Today’s learning really built the foundation for working with Docker practically.
Understanding basic commands and Dockerfile instructions is crucial before diving into building and deploying real-world applications using Docker.
Stay tuned for Day 3 where I’ll move deeper into image creation and container management! 🚀
🔖 Tags
#Docker #DockerCommands #Dockerfile #DevOps #Containers #LearningSeries
Subscribe to my newsletter
Read articles from BHASHWANTH PALUKURI directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
