Isaac.

devops

Docker Basics

Get started with Docker: containers, images, and how to containerize your applications.

By Emem IsaacJuly 17, 20222 min read
#docker#containers#containerization#devops#virtualization
Share:

A Simple Analogy

Docker containers are like shipping containers. They package your application and everything it needs (code, runtime, libraries) into a standardized box. This box runs the same way everywhere—on your laptop, a server, or the cloud.


What Is Docker?

Docker is a containerization platform that packages applications and their dependencies into isolated, lightweight containers. Containers are portable, reproducible, and more efficient than virtual machines.


Why Use Docker?

  • Consistency: "Works on my machine" → "Works everywhere"
  • Isolation: Applications don't interfere with each other
  • Efficiency: Lightweight compared to full VMs
  • Scalability: Easy to deploy multiple instances
  • Simplifies DevOps: Single image → multiple environments

Images vs. Containers

| Concept | Meaning | |---------|---------| | Image | Blueprint (read-only template) | | Container | Running instance of an image |


Basic Workflow

1. Create a Dockerfile

FROM node:18
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]

2. Build an Image

docker build -t my-app:1.0 .

3. Run a Container

docker run -p 3000:3000 my-app:1.0

Key Docker Commands

docker images                    # List images
docker ps                       # List running containers
docker ps -a                    # List all containers
docker logs <container-id>      # View container logs
docker exec -it <id> bash       # Enter container shell
docker stop <container-id>      # Stop container
docker rm <container-id>        # Remove container

Practical Example

# ASP.NET Core API
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["MyApi.csproj", "."]
RUN dotnet restore "MyApi.csproj"
COPY . .
RUN dotnet build "MyApi.csproj" -c Release -o /app/build

FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app
COPY --from=build /app/build .
EXPOSE 80
ENTRYPOINT ["dotnet", "MyApi.dll"]

Run and check logs:

docker build -t my-api:1.0 .
docker run -p 80:80 my-api:1.0
docker logs <container-id>

Related Concepts to Explore

  • Docker Compose (multi-container apps)
  • Docker Registry and Docker Hub
  • Container orchestration (Kubernetes)
  • Networking and volumes in Docker

Summary

Docker enables developers to package, ship, and run applications reliably across any environment. Master Dockerfile creation and basic commands to get started with containerization and modern DevOps practices.

Share:

Written by Emem Isaac

Expert Software Engineer with 15+ years of experience building scalable enterprise applications. Specialized in ASP.NET Core, Azure, Docker, and modern web development. Passionate about sharing knowledge and helping developers grow.

Ready to Build Something Amazing?

Let's discuss your project and explore how my expertise can help you achieve your goals. Free consultation available.

💼 Trusted by 50+ companies worldwide | ⚡ Average response time: 24 hours