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:

CommandPurpose
docker --versionCheck the installed Docker version
docker pull <image>Download an image from Docker Hub
docker imagesList all downloaded images
docker run <image>Run a container from an image
docker psList running containers
docker ps -aList 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> bashAccess 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:

InstructionPurpose
FROMSets the base image for building the new image
RUNExecutes commands inside the image during build time
CMDProvides default commands to run when a container is created
LABELAdds metadata to the image (like version, description)
EXPOSEInforms Docker that the container listens on specific network ports
ENVSets environment variables
COPYCopies files/folders from the local machine to the container
ADDSimilar to COPY but can handle remote URLs and unpack archives
WORKDIRSets the working directory inside the container
ENTRYPOINTConfigures 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

0
Subscribe to my newsletter

Read articles from BHASHWANTH PALUKURI directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

BHASHWANTH PALUKURI
BHASHWANTH PALUKURI