BetaIT-Hub is in early access — your feedback helps us improve. Use the chat or email [email protected]

Tutorials/CONTAINERS/Getting Started with Docker: A Practical Guide
BeginnerCONTAINERS5 min read46 views

Getting Started with Docker: A Practical Guide

Learn Docker fundamentals — install Docker, understand images and containers, run your first container, and write a basic Dockerfile for your own application.

A
adminEliteStaff
Published 65d ago

Getting Started with Docker: A Practical Guide

Docker makes it easy to package applications and their dependencies into containers that run anywhere. This guide covers everything you need to get started.

Prerequisites

  • A Linux server or Windows/Mac with Docker Desktop
  • Basic terminal knowledge

Step 1: Install Docker

On Ubuntu/Debian:

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $USER

Log out and back in for the group change to take effect.

Verify installation:

docker --version
docker run hello-world

Step 2: Understand Key Concepts

  • Image — A read-only template with your application and dependencies
  • Container — A running instance of an image
  • Dockerfile — Instructions to build an image
  • Volume — Persistent storage for containers
  • Network — Communication between containers

Step 3: Run Your First Container

# Run an Nginx web server
docker run -d -p 8080:80 --name my-web nginx

Check running containers

docker ps

View logs

docker logs my-web

Stop the container

docker stop my-web

Visit http://localhost:8080 to see the Nginx welcome page.

Step 4: Write a Dockerfile

Create a simple Node.js application:

mkdir my-app && cd my-app

Create app.js:

const http = require('http');
const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello from Docker!');
});
server.listen(3000, () => console.log('Server running on port 3000'));

Create Dockerfile:

FROM node:20-alpine
WORKDIR /app
COPY app.js .
EXPOSE 3000
CMD ["node", "app.js"]

Build and run:

docker build -t my-app .
docker run -d -p 3000:3000 my-app

Step 5: Docker Compose

Create docker-compose.yml for multi-container apps:

version: '3.8'
services:
  web:
    build: .
    ports:
      - "3000:3000"
  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: secret
    volumes:
      - pgdata:/var/lib/postgresql/data

volumes: pgdata:

docker compose up -d
docker compose logs
docker compose down

Essential Commands Cheat Sheet

  • docker ps — List running containers
  • docker ps -a — List all containers
  • docker images — List images
  • docker exec -it bash — Shell into a container
  • docker rm — Remove a container
  • docker rmi — Remove an image
  • docker system prune — Clean up unused resources

Conclusion

You now understand Docker fundamentals and can build, run, and manage containers. Next steps: explore Docker networking, multi-stage builds, and container orchestration with Kubernetes.

Comments (0)

No comments yet. Be the first to share your thoughts.