Posts for: #Hands_On

Docker Full Notes

What is Docker?

  • Docker is an open platform for developing, shipping and running applications.
  • Docker is a platform which packages an application and all its dependencies together in the form of containers.

What problem does Docker solve?

The main problem it solves is dependency management. Image Description


Docker Architecture

Image Description


Some Terms to Understand

  1. Docker Daemon: Daemon is a program which runs on our computer and manages docker containers.
  2. Docker file: It is a text document which contains all the commands that a user can call on the command line to assemble an image.
  3. Images: Template to create docker container.
  4. Container: Running instance of docker image.Containers hold entire package to run application.

Basic Commands for Docker

  • Check the version
docker -v
  • pull image
docker pull <image-name>
  • check all the images
docker images
  • search images
docker search <image-name>
  • container creation
docker run <image-name>
  • list all the running containers
docker ps
  • list all the running + stopped containers
docker ps -a
  • run container in background(detached mode) + change the name of container.
docker run --name <custom-name> -d <image-name/image-id>
  • run container in -it {interactive-mode}, your container will run continuously
docker run --name <custom-name> -it -d <image-id/name> 
  • to execute the command inside your container
docker exec -it <container-id> command{python3/bash/java/cpp} 
  • get all the information about the container
docker inspect <container-id>
  • stop the running container
docker stop <containerName>
  • remove image
docker rm <image-name>
  • to restart the running container
docker restart <container-id>

My-SQL Image Commands

  • get the image
docker install mysql
  • run the mysql container
docker run --name <custome-mysql-name> -e MYSQL_ROOT_PASSWORD=<give-a-pass> -d mysql
  • use commands inside mysql container
docker exec -it <custom-sql-name> <command-type>

Docker for Touchstone MCQ Test

1. Docker Basics

  • What is Docker?
  • Benefits of using Docker
  • Docker vs Virtual Machines
  • Docker Architecture
    • Docker Engine
    • Docker Daemon
    • Docker Client

2. Docker Images

  • What is a Docker Image?
  • Layers in Docker Images
  • Docker Hub and Image Registries
  • Pulling Images
    docker pull
  • Listing Images
    docker images
  • Removing Images
    docker rmi
  • Custom Images using Dockerfile
    (See Dockerfile section below)

3. Docker Containers

  • What is a Container?
  • Creating Containers
    docker run
  • Listing Containers
    docker ps, docker ps -a
  • Starting/Stopping/Removing Containers
    docker start, docker stop, docker rm
  • Inspecting Containers
    docker inspect
  • Container Lifecycle
  • Running containers in detached mode
    -d
  • Executing commands inside containers
    docker exec, docker attach
  • Logs and Terminal access
    docker logs, docker exec -it

4. Dockerfile (Creating Custom Images)

  • What is a Dockerfile?
  • Basic Dockerfile Instructions
    • FROM
    • RUN
    • COPY
    • ADD
    • CMD
    • ENTRYPOINT
    • EXPOSE
    • ENV
    • WORKDIR
  • Building Image from Dockerfile
    docker build
  • Best practices
    • Minimizing layers
    • Using .dockerignore

5. Docker Volumes (Data Persistence)

  • What is a Volume?
  • Types
    • Volumes
    • Bind Mounts
  • Creating Volumes
    docker volume create
  • Mounting Volumes to Containers
    -v or --mount
  • Inspecting Volumes
    docker volume inspect
  • Volume Persistence and Sharing between Containers

6. Docker Networking

  • Default Docker Networks
    • bridge
    • host
    • none
  • Creating Custom Networks
    docker network create
  • Connecting Containers to Networks
    --network
  • Inspecting Networks
    docker network inspect
  • Communication between containers
    Via network name

7. Docker Compose (Multi-container Applications)

  • What is Docker Compose?
  • docker-compose.yml file structure
    • version
    • services
    • build
    • ports
    • volumes
    • depends_on
    • networks
  • Running with Compose
    docker-compose up, docker-compose down
  • Building and Rebuilding
    docker-compose build, docker-compose up --build
  • Scaling services
    docker-compose up --scale
  • Use cases and benefits
Read more →

PL SQL Questions HandsOn

📘 PL/SQL Practice Guide: Functions, Procedures, Triggers

📌 Functions in PL/SQL

🔹 Syntax

CREATE OR REPLACE FUNCTION function_name (
    param1 IN data_type,
    param2 IN data_type
) RETURN return_data_type IS
BEGIN
    -- logic
    RETURN some_value;
END;
/

✅ Practice Questions with Solutions

1. Check Even or Odd

CREATE OR REPLACE FUNCTION check_even_odd(n IN NUMBER) RETURN VARCHAR2 IS
BEGIN
    IF MOD(n, 2) = 0 THEN
        RETURN 'EVEN';
    ELSE
        RETURN 'ODD';
    END IF;
END;
/

2. Get Maximum of Two Numbers

CREATE OR REPLACE FUNCTION get_max(a IN NUMBER, b IN NUMBER) RETURN NUMBER IS
BEGIN
    IF a > b THEN
        RETURN a;
    ELSE
        RETURN b;
    END IF;
END;
/

3. Count Vowels in a String

CREATE OR REPLACE FUNCTION count_vowels(str IN VARCHAR2) RETURN NUMBER IS
    count NUMBER := 0;
    ch CHAR;
BEGIN
    FOR i IN 1..LENGTH(str) LOOP
        ch := LOWER(SUBSTR(str, i, 1));
        IF ch IN ('a', 'e', 'i', 'o', 'u') THEN
            count := count + 1;
        END IF;
    END LOOP;
    RETURN count;
END;
/

4. Check Palindrome

CREATE OR REPLACE FUNCTION is_palindrome(str IN VARCHAR2) RETURN VARCHAR2 IS
    reversed_str VARCHAR2(1000) := '';
BEGIN
    FOR i IN REVERSE 1..LENGTH(str) LOOP
        reversed_str := reversed_str || SUBSTR(str, i, 1);
    END LOOP;

    IF LOWER(str) = LOWER(reversed_str) THEN
        RETURN 'YES';
    ELSE
        RETURN 'NO';
    END IF;
END;
/

5. Sum of Digits

CREATE OR REPLACE FUNCTION sum_of_digits(n IN NUMBER) RETURN NUMBER IS
    sum NUMBER := 0;
    digit NUMBER;
    num NUMBER := n;
BEGIN
    WHILE num > 0 LOOP
        digit := MOD(num, 10);
        sum := sum + digit;
        num := FLOOR(num / 10);
    END LOOP;
    RETURN sum;
END;
/

🔧 Procedures in PL/SQL

🔹 Syntax

CREATE OR REPLACE PROCEDURE procedure_name (param1 IN/OUT data_type) IS
BEGIN
    -- logic
END;
/

✅ Practice Questions with Solutions

1. Procedure to Print Square

CREATE OR REPLACE PROCEDURE print_square(n IN NUMBER) IS
BEGIN
    DBMS_OUTPUT.PUT_LINE('Square: ' || (n * n));
END;
/

2. Procedure to Update Employee Salary

CREATE OR REPLACE PROCEDURE increase_salary(empId IN NUMBER) IS
BEGIN
    UPDATE employees
    SET salary = salary * 1.10
    WHERE emp_id = empId;
    COMMIT;
END;
/

3. Procedure with OUT Parameter for Factorial

CREATE OR REPLACE PROCEDURE find_factorial(n IN NUMBER, result OUT NUMBER) IS
    fact NUMBER := 1;
BEGIN
    FOR i IN 1..n LOOP
        fact := fact * i;
    END LOOP;
    result := fact;
END;
/

🔥 Triggers in PL/SQL

🔹 Syntax

CREATE OR REPLACE TRIGGER trigger_name
BEFORE/AFTER INSERT/UPDATE/DELETE ON table_name
FOR EACH ROW
BEGIN
    -- logic
END;
/

✅ Practice Questions with Solutions

1. BEFORE INSERT Trigger

CREATE OR REPLACE TRIGGER trg_set_created_at
BEFORE INSERT ON students
FOR EACH ROW
BEGIN
    :NEW.created_at := SYSDATE;
END;
/

2. AFTER UPDATE Trigger for Salary Audit

CREATE OR REPLACE TRIGGER trg_salary_audit
AFTER UPDATE OF salary ON employees
FOR EACH ROW
BEGIN
    INSERT INTO salary_audit(emp_id, old_salary, new_salary, change_date)
    VALUES(:OLD.emp_id, :OLD.salary, :NEW.salary, SYSDATE);
END;
/

3. BEFORE DELETE Trigger to Prevent Deletion

CREATE OR REPLACE TRIGGER trg_prevent_delete
BEFORE DELETE ON departments
FOR EACH ROW
BEGIN
    RAISE_APPLICATION_ERROR(-20001, 'Deletion is not allowed on departments table.');
END;
/

📚 Additional Practice Questions

🔧 Functions

🔹 6. Reverse a String

Question: Write a function to reverse a given string.

Read more →