Thursday, 30 January 2025

4 - Quick Docker - Taste!

10-Minute Docker Tutorial: A Whirlwind Tour

This tutorial provides a rapid introduction to essential Docker concepts and commands. It's designed to get you started quickly.

1. What is Docker? (30 seconds)

Docker packages applications and their dependencies into containers. These containers run consistently across any machine with Docker installed, eliminating "works on my machine" issues. Think of them as standardized shipping containers for your software.

2. Installing Docker (1 minute)

  • Linux: Follow the official instructions for your distribution (e.g., Ubuntu, CentOS). Search for "install docker <your_distro>".
  • macOS/Windows: Docker Desktop is the recommended solution. Download and install it from the official Docker website.

3. Checking Docker Installation (15 seconds)

Open your terminal and type:

Bash
docker version

If Docker is installed correctly, you'll see version information.

4. Running a Container (1 minute)

Let's run a simple "hello world" container:

Bash
docker run hello-world

Docker will download the hello-world image (if you don't have it already) and run a container from it. You should see a greeting message.

5. Listing Containers (30 seconds)

See which containers are running:

Bash
docker ps

This shows running containers. To see all containers (including stopped ones):

Bash
docker ps -a

6. Stopping and Removing Containers (45 seconds)

To stop a running container:

Bash
docker stop <container_id_or_name>

To remove a stopped container:

Bash
docker rm <container_id_or_name>

Find the <container_id_or_name> using docker ps -a.

7. Working with Images (1 minute)

See which images you have downloaded:

Bash
docker images

Download an image from Docker Hub (a public repository):

Bash
docker pull <image_name>:<tag>  # e.g., docker pull ubuntu:latest

Remove an image:

Bash
docker rmi <image_id_or_name>

8. Running a Web Server (2 minutes)

Let's run a simple Nginx web server:

Bash
docker run -p 8080:80 nginx

This maps port 8080 on your machine to port 80 in the container (where Nginx is listening). Open your web browser and go to http://localhost:8080. You should see the Nginx welcome page. Stop the container when you're done.

9. Building Your Own Image (2 minutes)

Create a directory (e.g., my-web-app). Inside, create an index.html file with some HTML content. Create a Dockerfile in the same directory:

Dockerfile
FROM nginx:latest
COPY . /usr/share/nginx/html

Build the image:

Bash
docker build -t my-web-app-image .

Run a container from your new image:

Bash
docker run -p 8081:80 my-web-app-image

Visit http://localhost:8081 to see your web app.

10. Docker Compose (1 minute)

Docker Compose simplifies running multi-container applications. Create a docker-compose.yml file:

YAML
version: "3.9"
services:
  web:
    build: .
    ports:
      - "80:80"

Run with:

Bash
docker-compose up -d  # -d for detached mode

Stop with:

Bash
docker-compose down

This has been a very quick introduction. There's much more to explore (volumes, networking, orchestration). But this should give you a taste of Docker's power and ease of use. Happy Docking!


Docker Demos from Github:

Demo For Llama Docker Pull from GIT::: 

git clone https://huggingface.co/spaces/harsh-manvar/llama-2-7b-chat-test # read me 

docker buildx  build --platform=linux/amd64  -t local-llm:v1 .

docker run -it -p 7860:7860 --platform=linux/amd64 -e HUGGING_FACE_HUB_TOKEN="YOUR_VALUE_HERE" local-llm:v1 python app.py

http://localhost:7860 

For GENAI stack Pl. Refer https://github.com/docker/genai-stack

No comments:

Post a Comment

Dockerize Agent -Document Processing

 Since you are using Flask in Agent.py , I will modify the Dockerfile and steps accordingly. [WIP] 1. Update the Dockerfile Create a Do...