đź’ˇ
This post serves as my notes from the DevOps Bootcamp by Techworld with Nana.
https://www.techworld-with-nana.com/devops-bootcamp

What Is Docker?

Docker is an open-source containerization platform that allows developers to package applications — along with all their dependencies and configurations — into portable, standardized containers.

Containers existed before Docker, but Docker made them accessible, consistent, and developer-friendly.

Why It Matters

  • Same app, same behavior across environments
  • Fast installation and deployment
  • Easier version management
  • Eliminates “it works on my machine” issues

What Is a Container?

A container is a lightweight, isolated environment for an application and its dependencies. It’s portable across machines and ideal for efficient development, shipment, and deployment.

Before Docker:
Manual setup, dependency conflicts, inconsistent environments.

After Docker:
Self-contained packages, predictable runtime, reproducible builds.

Docker Images vs Containers

Docker Image Docker Container
Blueprint of an app Running instance of that blueprint
Static, layered artifact Active environment executing the app
Can be shared, versioned, and stored Exists while running (ephemeral unless persisted)

Containers vs Virtual Machines

Containers Virtual Machines
Share the host OS kernel Each VM includes a full OS
Faster startup Slower startup
Lightweight Heavy
App-level isolation Hardware-level isolation
đź’ˇ
Note: Linux containers can’t run natively on Windows hosts — Docker Desktop bridges that gap using Windows Subsystem for Linux or Hyper-V.

Docker Architecture

Docker consists of:

  1. Client (CLI): Interface to run Docker commands
  2. Server (Daemon): Executes build/run tasks
  3. Registry: Stores and distributes images

It also manages:

  • Images and containers
  • Networking between containers
  • Data persistence via volumes

Essential Docker Commands

Command Purpose
docker run Create and start a container
docker pull Download an image
docker ps / docker ps -a List running/all containers
docker images List local images
docker logs <container> View container logs
docker exec -it <container> bash Open a terminal inside a running container
docker stop/start Manage container lifecycle

Ports in Docker

Since multiple containers can run simultaneously, Docker uses port mapping:

docker run -p 8080:80 my-app
  • Host port: 8080
  • Container port: 80

Now your app is accessible at localhost:8080.

Workflow With Docker

  • Build image from a Dockerfile
  • Run container from that image
  • Map ports and mount volumes as needed
  • Push/pull images from repositories
  • Deploy containers to remote servers

Docker Compose

Docker Compose helps manage multi-container applications with a single YAML file.

Example:

version: '3'
services:
  web:
    build: .
    ports:
      - "8080:80"
  db:
    image: mongo:4.2

Benefits:

  • Shared network automatically created
  • Centralized configuration
  • Easier updates and orchestration

Dockerfile Basics

A Dockerfile defines how to build an image:

FROM node:18-alpine
WORKDIR /app
COPY . .
RUN npm install
CMD ["npm", "start"]

Common Instructions

  • FROM – Base image
  • COPY / ADD – Add files
  • RUN – Execute build commands
  • EXPOSE – Declare ports
  • CMD / ENTRYPOINT – Start the app

Each instruction creates a new layer, making builds efficient through caching.

Private & Public Repositories

Public: DockerHub
Private: AWS ECR, Azure Container Registry, Nexus, etc.

To push to a private registry:

docker login <registry-url>
docker tag my-app:1.0 <registry-url>/my-app:1.0
docker push <registry-url>/my-app:1.0

Docker Volumes

By default, container data disappears when the container is removed. Volumes solve this by persisting data outside the container.

Types of Volumes

Type Description
Host Volume Maps a specific host directory
Anonymous Volume Created automatically (not referenced by name)
Named Volume Managed by Docker, referenced by name

Example:

docker run -v mydata:/var/lib/mysql/data mysql

Or inside docker-compose.yaml:

volumes:
  dbdata:
services:
  db:
    image: mongo
    volumes:
      - dbdata:/data/db

Docker Best Practices

Security

  • Use official images
  • Avoid leaking credentials into images
  • Run as non-root users
  • Regularly scan for vulnerabilities

Efficiency

  • Use minimal base images (e.g., Alpine)
  • Cache layers intelligently
  • Add a .dockerignore
  • Use multi-stage builds for smaller, cleaner images

Demo Projects

Use Docker for Local Development

Technologies Used

  • Docker
  • Node.js
  • MongoDB
  • MongoExpress

Summary of Steps

  1. Create Dockerfile for Nodejs application and build Docker image.
  2. Run Nodejs application in Docker container and connect to MongoDB database container locally.
  3. Also run MongoExpress container as a UI of the MongoDB database.

Search and Pull Docker Images

Most of the public images are available through https://hub.docker.com/.

  1. Go to https://hub.docker.com/
  2. Search for mongo image.
Docker Hub Mongo Image
  1. Search for mongo-express image.
Docker Hub Mongo Express Image
  1. Pull the latest image for each.
docker pull mongo
docker pull mongo-express
docker pull

Run Mongo and Mongo-Express Docker Images


Docker Compose - Running Multiple Services

Technologies Used

  • Docker
  • MongoDB
  • MongoExpress

Summary of Steps

  1. Write Docker Compose file to run MongoDB and MongoExpress containers.

Dockerize Nodejs Application

Technologies Used

  • Docker
  • Node.js

Summary of Steps

  1. Write Dockerfile to build a Docker image for a Nodejs application.

Persist Data with Docker Volumes

Technologies Used

  • Docker
  • Node.js
  • MongoDB

Summary of Steps

  1. Persist data of a MongoDB container by attaching a Docker volume to it.

Create Docker Repository on Nexus and Push to It

Technologies Used

  • Docker
  • Nexus
  • DigitalOcean
  • Linux

Summary of Steps

  1. Create Docker hosted repository on Nexus.
  2. Create Docker repository role on Nexus.
  3. Configure Nexus, DigitalOcean Droplet and Docker to be able to push to Docker repository.
  4. Build and Push Docker image to Docker repository on Nexus.

Deploy Docker Application on a Server with Docker Compose

Technologies Used

  • Docker
  • AmazonECR
  • Node.js
  • MongoDB
  • MongoExpress

Summary of Steps

  1. Copy Docker-Compose file to remote server.
  2. Login to private Docker registry on remote server to fetch our app image.
  3. Start our application container with MongoDB and MongoExpress services using docker compose.

Deploy Nexus as Docker Container

Technologies Used

  • Docker
  • Nexus
  • DigitalOcean
  • Linux

Summary of Steps

  1. Create and Configure Droplet.
  2. Set up and run Nexus as a Docker container.