Soft introduction from the Dokar for Azigar Developers

by SkillAiNest

Soft introduction from the Dokar for Azigar DevelopersSoft introduction from the Dokar for Azigar Developers
Photo by Author | Ideogram

. Introduction

You just pushed your app in production, and suddenly everything is broken. The app worked perfectly on your laptop, passed all the tests in the CI, but now it is throwing mysterious import errors in production. Familiar sound? Or maybe you’re riding on a new developer who just tries to run your project locally. They are on Windows, you designed on Mac, operates the production server Ubuntu, and somehow have different version and contradictory package installations.

We are all there, instead of building features, we debugging specific environment issues. Doctor This dirt solves its entire application environment in a container by package in a container that runs alike. No more “works on my machine” no excuse. Do not spend any more weeks while debugging deployment issues. This article introduces you to the Doker and how you can use the Doker to facilitate application development. You will also learn how to contain a simple application using a Doker.

🔗 🔗 Link from the code on the Gut Hub

. How does a Dokar work and why do you need it

Understand the Doker according to the shipping containers, but your code. When you contain containers to an Ezar app, you just don’t packaging your code. You are packaging the entire run -time environment: specific version, all your dependence, system libraries, environmental variables, and even the operating system that your app is expected.

Result? Your app operates on your laptop, your partner’s Windows machine, staging server, and production. Every time but how do you do it?

Well, when you are containing the apps with the Doker, you do the following. You pack your app in a portable article called “image”. Then, you start “containers” – run the example of photos – and run your applications in a containerized environment.

. Building an Azigar Web API

Instead of starting with toy examples, let’s contain a realistic request. We will build a simple PhostepTodo API Based (with uvicorn As a asgi server) that shows the patterns you will use in real projects, and will use pydantic To verify data.

In your project directory, a requirement. Create a TXT File:

fastapi==0.116.1
uvicorn(standard)==0.35.0
pydantic==2.11.7

Now let’s create a basic app structure:

# app.py
from fastapi import FastAPI
from pydantic import BaseModel
from typing import List
import os

app = FastAPI(title="Todo API")
todos = ()
next_id = 1

Add the data model:

class TodoCreate(BaseModel):
    title: str
    completed: bool = False

class Todo(BaseModel):
    id: int
    title: str
    completed: bool

Create Health Check and Point:

@app.get("
def health_check():
    return {
        "status": "healthy",
        "environment": os.getenv("ENVIRONMENT", "development"),
        "python_version": os.getenv("PYTHON_VERSION", "unknown")
    }

Include basic Todo Enablement:

@app.get("/todos", response_model=List(Todo))
def list_todos():
    return todos

@app.post("/todos", response_model=Todo)
def create_todo(todo_data: TodoCreate):
    global next_id
    new_todo = Todo(
        id=next_id,
        title=todo_data.title,
        completed=todo_data.completed
    )
    todos.append(new_todo)
    next_id += 1
    return new_todo

@app.delete("/todos/{todo_id}")
def delete_todo(todo_id: int):
    global todos
    todos = (t for t in todos if t.id != todo_id)
    return {"message": "Todo deleted"}

Finally, add the server start -up code:

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)

If you drive it locally pip install -r requirements.txt && python app.pyYou have an API running locally. Now let’s go ahead to contain the application.

. Writing your first postponement

You have your app, you have a list of requirements, and you have a specific environment to run the app. So how do you go to a dock image with different ingredients that include both your code and dependence? You can explain it by writing a dock file for your request.

Think of it as a synthesis of creating a picture from different components of your project. Create a dock file in your project directory (no extension).

# Start with a base Python image:
FROM python:3.11-slim

# Set environment variables:
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    ENVIRONMENT=production \
    PYTHON_VERSION=3.11

# Set up the working directory:
WORKDIR /app

# Install dependencies (this order is important for caching):
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy your application code:
COPY . .

# Expose the port and set the startup command:
EXPOSE 8000
CMD ("python", "app.py")

This document file makes a web application container. It uses the image of Azigar 3.11 (slim version) as a base, sets a working directory, installs dependence on requirements. TTST, copying the app code, exposes the port 8000, and operates the application. python app.py. The structure follows the best methods by installing dependent before copying the code to use Dooker’s layer catching.

. To make and run your first container

Now we build and run our containerized application:

# Build the Docker image
docker build -t my-todo-app .

# Run the container
docker run -p 8000:8000 my-todo-app

When you run away docker buildYou will see that every line in your doer file is made as a layer. The first construction may take a little time as the Doker downloads the image of the base and install your dependence.

âš  Use docker buildx build Using a blood cut to create a picture from the instructions in the poster file.

-t my-todo-app The flag tags your image with a better name instead of random hash. -p 8000:8000 Part Maps Port 8000 on your host machine within 8000 containers.

You can visit To see if your API is running inside a container. The same container will operate on any machine equally in which the Doker is installed.

. Essential Essential Dooker Commands of Daily Use

These are the Dokar Commands you will often use:

# Build an image
docker build -t myapp .

# Run a container in the background
docker run -d -p 8000:8000 --name myapp-container myapp

# View running containers
docker ps

# View container logs
docker logs myapp-container

# Get a shell inside a running container
docker exec -it myapp-container /bin/sh

# Stop and remove containers
docker stop myapp-container
docker rm myapp-container

# Clean up unused containers, networks, images
docker system prune

. Some dockers are important to the best procedure

After working in production with the Doker, here are the behaviors that make a difference.

Always use specific version tags for base images:

# Instead of this
FROM python:3.11

# Use this
FROM python:3.11.7-slim

Create .dockerignore File to delete unnecessary files:

__pycache__
*.pyc
.git
.pytest_cache
node_modules
.venv
.env
README.md

Press your photos by clearing the package managers:

RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

Always run the container as non -root users in production.

. Wrap

This tutorial covers the basic principles, but the Doker’s ecosystem is very wide. Here are the next areas to find. For the deployment of production, learn about the container orchestration platform Cabinets Or cloud -related specific services such as AWS Flexible Container Service (ECS)For, for, for,. Google Cloud RunOr Azure Container Example.

Discover Dokar’s security features, including Secret Management, Image Scanning, and Route Lace Doker. Learn about high -speed construction and improving small -sized LOC Doker images. Continuous integration/continuous delivery (CI/CD) Systems using automatic blood and deployment .Shin pipelines such as Gut Hub Actions And Gut Lab CI.

Happy learning!

Pray Ca Is a developer and technical author from India. She likes to work at the intersection of mathematics, programming, data science, and content creation. The fields of interest and expertise include dupas, data science, and natural language processing. She enjoys reading, writing, coding and coffee! Currently, they are working with the developer community to learn and share their knowledge with the developer community by writing a lesson, how to guide, feed and more. The above resources review and coding also engages lessons.

You may also like

Leave a Comment

At Skillainest, we believe the future belongs to those who embrace AI, upgrade their skills, and stay ahead of the curve.

Get latest news

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

@2025 Skillainest.Designed and Developed by Pro