7 Amazing Docker Networking Tips for Ultimate Container Performance

Docker part-1

Docker 

Continue learning Docker in this advanced guide. Explore branching, merging, and squashing with real-world Git workflow examples.

 image:-

A  container image  a lightweight, standalone, and executable software package that contains:

  • Everything needed to run an application, including:

    • Source code

    • Dependencies

    • Libraries

    • Configuration files

    • Runtime environment (like Python, Node.js, etc.)

    • OS-level files (minimal, like from Ubuntu, Alpine)

Docker part-2

Think of it like a blueprint for containers.
 You build containers from images.

Example

container file
# container file to build a Python app image
FROM python:3.10-slim
COPY app.py /app.py
CMD ["python", "app.py"]

Then run:

bash
container build -t my-python-app .
container run my-python-app

Key Commands

bash
container images # List all images
container build .
# Build image from container file
container rmi <image>
# Remove an image
container pull <image>
# Download image from container Hub

Real-Life Analogy

Image = Recipe
Container = Cooked dish made using the recipe

  Docker Custom Image

A custom Docker image is one that you create yourself, tailored to your application’s specific needs.
Instead of using a prebuilt image like python:3.10, you define everything — the OS, libraries, dependencies, and your code — using a container file.

Structure

You create a container file, which acts as instructions to build the image.

Example: Create a Custom Image for a Node.js App

1. Your app folder structure:

pgsql
my-app/

├── container file
├── package.json
└── index.js

2. container file content:

container file
# Base image
FROM node:18-alpine
# Create app directory
WORKDIR /app
# Copy files
COPY package*.json ./
RUN npm install
COPY . .
# App runs on port 3000
EXPOSE 3000
# Command to run the app
CMD ["node", "index.js"]

Docker Tutorial 4: Exporting Container and Saving Image | by Sik-Ho Tsang | Medium

1. docker saveExport Docker Image

bash
container save -o <file-name>.tar <image-name>

Example:

bash
container save -o myapp.tar my-custom-node-app

This creates a file myapp.tar containing the full container image (including all layers).

2. docker loadImport Docker Image

bash
container load -i <file-name>.tar

Example:

bash
container load -i myapp.tar

Use Case Example

Let’s say you want to move a custom image from your laptop to another server:

  1. Save the image:

    bash
    do container image save -o myapp.tar my-custom-node-app
  2. Copy the file (via USB, scp, etc.) to the target server.

  3. Load the image on the server:

    bash
    container load -i myapp.tar
  4. Verify it’s available:

    bash
    container image

Docker Registry

A Docker Registry is a storage and distribution system for container images.

It allows you to:

  • Store container images

  • Share them with others

  • Pull them to run containers anywhere

Types of regisry:

Type Examples
Public Registry Docker Hub, GitHub Container Registry
Private Registry Your own on-premise or cloud-based registry (like AWS ECR, GCR)

Most Common: container Hub

  • Official public registry by container

  • Contains official images (e.g., ubuntu, nginx, mysql)

  • Free & paid plans

Website: Click Here

How It Works

  1. Build your image:

    bash
    container build -t username/my-app .
  2. Login to container Hub:

    bash
    container login
  3. Push your image to the registry:

    bash
    container push username/my-app
  4. Pull image on another machine:

    bash
    container pull username/my-app

Registry vs Repository vs Image

Term Meaning
Registry Whole storage system
Repository A collection of versions of an image (username/my-app)
Image A specific version (tag) like username/my-app:1.0

Private container Registry (Self-Hosted)

Run your own registry locally or in a data center:

bash
container run -d -p 5000:5000 --name registry registry:2

Now push images to localhost:5000/my-image.

Registry Commands Overview

Command Description
docker login Authenticate with a registry
docker push <image> Upload image to a registry
docker pull <image> Download image from a registry
docker tag <image> <repo/image> Tag image for pushing

Analogy

Registry = App Store
Repository = Individual app page
Image = Specific app version (v1.0, v2.0)

Dockerfile

A Dockerfile is a plain text file that contains a set of instructions used by container to build a custom image.

What is Dockerfile? - GeeksforGeeks

Why Use a Dockerfile?

  • Automate the creation of container images

  • Ensure consistency across environments (dev, test, prod)

  • Easily share your app with its environment

Basic Structure :

container file
# 1. Base Image
FROM node:18
# 2. Set working directory inside container
WORKDIR /app
# 3. Copy files
COPY package*.json ./
RUN npm install
COPY . .
# 4. Expose port (optional but good practice)
EXPOSE 3000
# 5. Command to run the app
CMD ["node", "index.js"]

 Container file Instructions (Most Common)

Instruction Purpose
FROM Sets the base image (e.g., Ubuntu, Python, Node.js)
WORKDIR Sets working directory in the container
COPY Copies files from host into image
RUN Executes commands while building the image
EXPOSE Documents which port the container will use
CMD Sets default command to run container

Example: Python App container file

container file
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "app.py"]

Build Image from container file

bash
container build -t my-python-app .

Run Container from Built Image

bash
container run -p 5000:5000 my-python-app

Real-Life Analogy

container file = Cooking recipe
container image = Prepared food
Container = Serving the dish (running app)

Best Practices

  • Use small base images like alpine for minimal size

  • Group COPY and RUN efficiently to avoid extra layers

  • Use container ignore to exclude unnecessary files

  • Pin versions in FROM, pip, npm etc. for reproducibility                                                                                                                                   

Previous