[th][in-progress] Basic Docker

󰃭 2025-02-10

Docker Components

What is docker ?

Docker คือแพลตฟอร์มที่ช่วยให้เราสามารถพัฒนา จัดส่ง และรัน applications ได้ในรูปแบบของ containers ซึ่งเป็นสภาพแวดล้อมที่แยกออกมาต่างหาก ทำให้แอพพลิเคชันของเราทำงานได้เหมือนกันในทุกๆ environment

Continue reading 


Docker Cheat sheet

󰃭 2025-02-10

Images

Building Images

# Build an image from a Dockerfile
docker build -t image_name:tag .

# Build with no cache
docker build --no-cache -t image_name:tag .

# Build with custom Dockerfile
docker build -f custom.dockerfile -t image_name:tag .

Managing Images

# List all images
docker images

# Remove an image
docker rmi image_name:tag

# Remove all unused images
docker image prune

# Pull an image from Docker Hub
docker pull image_name:tag

# Push an image to Docker Hub
docker push image_name:tag

# Tag an image
docker tag source_image:tag target_image:tag

Containers

Running Containers

# Run a container
docker run image_name:tag

# Run with interactive terminal
docker run -it image_name:tag

# Run in detached mode
docker run -d image_name:tag

# Run with port mapping
docker run -p host_port:container_port image_name:tag

# Run with volume mounting
docker run -v host_path:container_path image_name:tag

# Run with environment variables
docker run -e VAR_NAME=value image_name:tag

# Run with custom name
docker run --name container_name image_name:tag

Managing Containers

# List running containers
docker ps

# List all containers (including stopped)
docker ps -a

# Stop a container
docker stop container_id/name

# Start a stopped container
docker start container_id/name

# Restart a container
docker restart container_id/name

# Remove a container
docker rm container_id/name

# Remove all stopped containers
docker container prune

# Execute command in running container
docker exec -it container_id/name command

Network

Managing Networks

# List networks
docker network ls

# Create a network
docker network create network_name

# Remove a network
docker network rm network_name

# Connect container to network
docker network connect network_name container_id/name

# Disconnect container from network
docker network disconnect network_name container_id/name

Volumes

Managing Volumes

# List volumes
docker volume ls

# Create a volume
docker volume create volume_name

# Remove a volume
docker volume rm volume_name

# Remove all unused volumes
docker volume prune

Docker Compose

Basic Commands

# Start services
docker-compose up

# Start in detached mode
docker-compose up -d

# Stop services
docker-compose down

# Stop and remove volumes
docker-compose down -v

# View service logs
docker-compose logs

# Scale services
docker-compose up -d --scale service_name=num_instances

System & Maintenance

System Commands

# Display system-wide information
docker info

# Show Docker disk usage
docker system df

# Remove unused data
docker system prune

# Remove all unused data (including volumes)
docker system prune -a --volumes

Logging & Debugging

Logs and Inspection

# View container logs
docker logs container_id/name

# Follow container logs
docker logs -f container_id/name

# Inspect container details
docker inspect container_id/name

# View container stats (CPU, memory, etc.)
docker stats container_id/name

Best Practices

  1. Always tag your images with specific versions
  2. Use .dockerignore to exclude unnecessary files
  3. Minimize the number of layers in your Dockerfile
  4. Use multi-stage builds for smaller final images
  5. Don’t run containers as root
  6. Use volumes for persistent data
  7. Clean up unused objects regularly
  8. Use docker-compose for multi-container applications

Common Dockerfile Instructions

FROM        # Base image
WORKDIR     # Set working directory
COPY        # Copy files from host to container
ADD         # Copy files, download URLs, and extract archives
RUN         # Execute commands
ENV         # Set environment variables
EXPOSE      # Expose ports
VOLUME      # Create mount point
CMD         # Default command
ENTRYPOINT  # Configure container executable

Note: Replace container_id/name, image_name:tag, and other placeholders with your actual values when using these commands.

Continue reading 


Neovim เคยเจอปัญหาช้าๆ ค้างๆ งงๆ มั้ย เราจะ Debug มันอย่างไร ?

󰃭 2024-10-13

เปิดไฟล์ที่ต้องการตรวจสอบ เช่น main.zig จากนั้นรันคำสั่งด้านล่าง

nvim main.zig
:profile start profile.log
:profile func *
:profile file *.

ทดสอบคำสั่ง เช่น เจอปัญหาว่า save :w แล้วค้าง จากนั้น pause profile และออกจาก Neovim

Continue reading 


Robot Framework Workshop #1 by น้องแชมป์

󰃭 2024-10-13

หลังจากที่มีน้องแชมป์มาสอนในทีมเกี่ยวกับ Test Automation ด้วย Robot Framework ไปแล้ว ก็เลยอยากจะมาเขียน Workshop ตัวนึงสำหรับพื้นฐานเกี่ยวกับ Robot Framework กัน

Continue reading 


[th][DONE] Basic React #1 V.1

󰃭 2024-10-12

Slide

สิ่งที่จะได้เรียนรู้ & Table of Contents

  • สร้างโปรเจค React ด้วย Vite
  • Create React Component
    • Ex. Create Input Text Component
    • Ex. Create Nested Component (Greeting Component , Input Text Component + Button)
  • React JSX
    • Display Primative Data
    • Display Object
    • Function in JSX
    • List in JSX
    • React Component Defination (Advanced)
    • Prepare for Next Create Search, List Components
  • Handler Funciton in JSX
  • React Props
  • React State & Hooks
    • useState
    • useEffect
  • What’s Next?

เตรียมความพร้อมก่อนเริ่มเขียน React

ติดตั้ง NodeJS and NPM เปลี่ยนมาใช้ pnpm

ตรวจสอบการติดตั้ง Node

Continue reading 


Neovim setup for Zig

󰃭 2024-10-12

เตรียมความพร้อมก่อนการเขียนภาษา Zig สำหรับ Neovim

Zig installation

ก่อนอื่นติดตั้ง Ziglang จาก https://ziglang.org/download/

ทดสอบการติดตั้ง

สร้าง directory zig_hello_world และเข้าไปยัง directory

Continue reading 