Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Docker Fundamentals on Ubuntu: From Installation to Container Management

Tech 1

Environment Prerequisites

Development and testing performed on Ubuntu 18.04.2 LTS (Bionic Beaver).

Core Architecture

Docker operates on a client-server model utilizing two primary abstractions:

  • Images: Read-only templates containing filesystem layers and application dependencies. Think of these as class definitions in object-oriented programming.
  • Containers: Runtime instances of images—encapsulated processes with isolated filesystems, network interfaces, and resource constraints.

Installation Procedures

First, purge legacy Docker packages to prevent conflicts:

sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install docker.io
sudo systemctl enable --now docker

Image Operations

Discover official repositories:

docker search postgres

Retrieve specific versions:

docker pull redis:7-alpine

Inventory local storage:

docker image ls --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"

Persistence operations:

# Export to tar archive
docker save -o ~/backups/webapp-v2.tar myregistry/webapp:v2.1

# Import from archive
docker load < ~/backups/webapp-v2.tar

# Create custom image from running container
docker commit -m "Added SSL certificates" -a "DevOps Team" web-server-01 production/nginx-ssl:v1.0

Remove artifacts:

docker rmi --force sha256:abc123...

Container Management

Initializing containers with resource constraints:

docker run -d \
  --name api-gateway \
  --hostname gateway-node \
  -p 8080:80 \
  -p 8443:443 \
  -v /var/log/nginx:/var/log/nginx \
  -e NODE_ENV=production \
  --restart unless-stopped \
  nginx:stable-alpine

Parameter reference:

  • -d: Detached mode (daemon)
  • --name: Human-readable identifier
  • -p HOST:CONTAINER: Port forwarding rules
  • -v HOST:CONTAINER: Bind mount volumes
  • -e: Environment variable injection
  • --restart: Auto-start policy

Interactive access:

# Preferred method: spawns new bash process
docker exec -u root -it api-gateway /bin/sh

# Alternative (attaches to PID 1, blocks when multiple clients connect):
docker attach api-gateway

Lifecycle control:

docker start api-gateway
docker restart api-gateway
docker stop -t 30 api-gateway  # Grace period before SIGKILL
docker rm -v api-gateway       # Remove container and anonymous volumes

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.