Sitemap
CodeToDeploy

Tech Insights | Careers | Jobs

Docker???

3 min readJan 21, 2026

--

Press enter or click to view image in full size
Image by Author

Docker Image

A Docker image is a built, read-only package.

It contains:

  • OS layer (Linux)
  • runtime (Node, etc.)
  • app code
  • dependencies
  • start command

Key points:

  • Images do not run
  • Images are templates
  • Images are created using a Dockerfile

Example:

docker build -t my-app .

This creates an image.

Docker Container

A Docker container is a running instance of an image.

Key points:

  • Containers run
  • Containers are isolated processes
  • You can start, stop, restart, delete them
  • Multiple containers can come from one image

Example:

docker run my-app

This starts a container from the image.

Relationship (important)

Dockerfile → Image → Container
  • Dockerfile defines how to build
  • Image is what gets built
  • Container is what actually runs

What is a Dockerfile?

A Dockerfile is a text file that tells Docker how to build an image (step by step).

Used to:

  • define runtime (Node, OS, etc.)
  • copy code
  • install dependencies
  • start the app

No extension because Docker looks for the exact name Dockerfile by convention.

server/Dockerfile

FROM node:18-alpine

WORKDIR /app

COPY package*.json ./
RUN npm install --production

COPY . .

EXPOSE 3001
CMD ["node", "server.js"]

What this does:

  • Uses a lightweight Node image
  • Installs dependencies
  • Copies application code
  • Starts the API server

Why order matters in Dockerfile

Docker builds line by line and caches layers.

Get Alember Shreesh’s stories in your inbox

Join Medium for free to get updates from this writer.

If a line changes:

  • that line and everything after it rebuilds

That’s why deps are copied before app code.

How Docker caching works

  • Each instruction = one layer
  • If nothing changed → Docker reuses cached layer
  • If something changed → rebuild from that point

Result:

  • Faster builds
  • Smaller rebuild scope

Dockerfile vs docker-compose.yml

  • Dockerfile → how to build one image
  • docker-compose.yml → how to run multiple containers together
Press enter or click to view image in full size

When to use what

  • Only Dockerfile → single service
  • Dockerfile + Compose → full-stack app
  • Only Compose → using prebuilt images

Docker Compose:

Docker Compose defines how containers are started, connected, configured, and stopped as a group.

services:
backend:
build: ./server
container_name: api
ports:
- "3001:3001"
env_file:
- ./server/.env
restart: unless-stopped

frontend:
build: ./client
container_name: web
ports:
- "80:80"
depends_on:
- backend
restart: unless-stopped

This keeps frontend and backend isolated but connected.

What actually happens

When you run:

docker compose up

Docker Compose:

1)Looks at docker-compose.yml

2) For each service:

  • builds an image (if build: is defined) OR
  • pulls an image (if image: is defined)

3) creates containers from those images

4) runs the containers together

Example:

services:
backend:
build: ./server
frontend:
image: nginx

What Compose does:

  • Builds one image for backend
  • Pulls one image for frontend
  • Runs two containers

Thank you for being a part of the community

Before you go:

Press enter or click to view image in full size

👉 Be sure to clap and follow the writer ️👏️️

👉 Follow us: Linkedin| Medium

👉 CodeToDeploy Tech Community is live on Discord — Join now!

Note: This Post may contain affiliate links.

--

--

Alember Shreesh
Alember Shreesh

Written by Alember Shreesh

I Love stories. I write about code, life, and the random thoughts that deserve a place on the page.