Docker Faqs

Docker Basics Simplified

💡 Docker Basics - Simplified for Everyone

🚀 What is Docker?

  • Docker helps you build, test, and run apps quickly and easily.
  • It puts your app and everything it needs into one container.
  • This makes sure the app works the same everywhere—on any computer.

⚙️ How Does Docker Work?

  • Docker is like a small operating system for running apps in containers.
  • You give it simple commands, and it handles everything behind the scenes.
  • It works across different machines, making your app run the same way every time.

💻 What is a Hypervisor?

  • A hypervisor lets many operating systems run on one machine at the same time.
  • It shares memory, CPU, and other resources with each one.
  • This is used to create virtual machines (VMs).

📦 What is a Docker Container?

  • A container is a small package with everything an app needs to run.
  • It makes your app portable and consistent, no matter where it runs.
  • Easy to move, start, stop, and scale.

🏗️ What are Docker’s Main Parts?

  • Docker Client: Where you type commands.
  • Docker Daemon: Does the work (runs containers, builds images).
  • Docker Registry: Stores Docker images (like Docker Hub).

🌐 Docker Networking Modes Explained

  • Bridge (Default): Containers talk to each other via a virtual bridge.
  • Host: Uses your computer’s network directly (no isolation).
  • None: No networking at all. Fully isolated.
  • Overlay: Used in Docker Swarm to connect containers on different machines.

🔗 How to Connect Two Containers?

Create a custom Docker network so containers can talk to each other by name:

docker network create mynetwork
docker run -d --net=mynetwork --name=container1 myapp
docker run -d --net=mynetwork --name=container2 myapp

Now, container1 can ping container2.

📁 Docker Volumes – Keeping Your Data Safe

  • Volumes: Docker-managed storage stored in /var/lib/docker/volumes/.
  • Bind Mounts: Link a folder from your host machine to the container.
  • Use volumes when you want persistent, easy-to-manage data.
docker volume create myvolume
docker run -d -v myvolume:/data myapp

📦 Docker Compose – Run Multiple Containers Easily

With one YAML file, you can spin up your app, database, and more!

version: '3'
services:
  web:
    image: nginx
    ports:
      - "80:80"
  db:
    image: postgres
    environment:
      - POSTGRES_PASSWORD=example

Run it with:

docker-compose up -d

☁️ Docker + AWS – A Perfect Match

  • Use Amazon ECS + Fargate to run containers without managing servers.
  • Store your images in Amazon ECR (Elastic Container Registry).
  • Integrate easily with CodePipeline for CI/CD.

📤 Push Docker Image to AWS ECR

aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin youraccount.dkr.ecr.us-east-1.amazonaws.com
docker tag myapp:latest youraccount.dkr.ecr.us-east-1.amazonaws.com/myapp:latest
docker push youraccount.dkr.ecr.us-east-1.amazonaws.com/myapp:latest

🛠️ Dockerfile – Build Custom Images

A Dockerfile is like a recipe to build your own Docker image.

FROM ubuntu:latest
RUN apt-get update && apt-get install -y nginx
COPY index.html /var/www/html/
CMD ["nginx", "-g", "daemon off;"]
  • FROM: Base OS image
  • RUN: Install packages
  • COPY: Add files
  • CMD: Start the app

🐞 Troubleshooting Docker Containers

  • docker logs mycontainer – See app logs
  • docker stats – Monitor resources
  • docker exec -it mycontainer sh – Go inside a container
  • docker inspect – Get container settings

💡 Tip: Avoid Memory Overuse in Containers

  • Limit memory: --memory=512m
  • Limit CPU: --cpus=1.0
  • Use Alpine images for lightweight containers

Comments