Tuesday, October 17, 2023

How to run a docker image without docker desktop installation in Windows 10 VM with virtulization and hyper-v enabled?

Installing WSL 2

  1. Open PowerShell as an administrator: Right-click the Windows Start button and select "Windows Terminal (Admin)" or "Command Prompt (Admin)."

  2. Enable the WSL feature:

    powershell
    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
  3. Enable the Virtual Machine Platform feature:

    powershell
    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  4. Restart your computer to complete the installation of the Virtual Machine Platform feature.

  5. After restarting, open PowerShell as an administrator again.

  6. Set WSL 2 as the default version:

    powershell
    wsl --set-default-version 2
  7. Install a Linux distribution of your choice from the Microsoft Store or by using the command-line. For example, to install Ubuntu:

    powershell
    wsl --install -d Ubuntu
  8. Initialize your newly installed Linux distribution and follow the prompts to set up a user and password.

WSL 2 is now installed and ready for use.

Installing Docker in WSL 2

To install Docker in WSL 2, follow these steps:

  1. Open a WSL 2 terminal.

  2. Run the following command:

    bash
    sudo apt update && sudo apt install docker.io

Running the Docker Image

To run a Docker image in WSL 2, follow these steps:

  1. Open a WSL 2 terminal.

  2. Run the following command to start a Docker container based on an image:

    bash
    docker run -it <image_name>

    For example, to run the hello-world image:

    bash
    docker run -it hello-world

    This will start a new container and display the message "Hello from Docker!" on the console.

  3. If you need to map specific ports, use the -p option. For instance, to run the hello-world image on port 80:

    bash
    docker run -it -p 80:80 hello-world

You can then access the container on port 80 of your machine.

Example

To run the nginx image in a Windows 10 VM with virtualization and Hyper-V enabled:

  1. Install WSL 2.

  2. Install Docker in WSL 2.

  3. Run the nginx image with the following command:

    bash
    docker run -it -p 80:80 nginx

You can access the Nginx web server on port 80 of your host machine.

Note: If you are running Docker in a VM, you may need to configure port forwarding to access the container from the host machine.

Sunday, June 4, 2023

Free workspace for you - Powered by Google

 Hi Folks,


I am writing this new blog about Free Workspace powered by Google.

If you are a data engineer, data scientist, or big data enthusiast, this will help you.


I am talking about Google Colab



Colab, or "Colaboratory", allows you to write and execute Python in your browser, with

  • Zero configuration required
  • Access to GPUs free of charge
  • Easy sharing

Whether you're a student, a data scientist or an AI researcher, Colab can make your work easier. Watch Introduction to Colab to learn more


So happy collab https://colab.research.google.com/


Some samples : https://github.com/msdevanms/pyspark_training




Wednesday, July 8, 2020

AWS Lambda Python - Build from your local machine - Upload as zip file - boto3 - import modules - Linux - Ubuntu

Hi Folks,

Now everything is PaaSified :)

So today we are going to looking in to creating and deploying AWS Lambda - Python from ZERO.


Here we go...



Step1. Create a new AWS Lambda using AWS portal or AWS CLI

Step 2. Install Python and pip in your local machine

Step 3. Create a new folder in your local machine

Step4. create a new file YOUR_FILE_NAME.py in that folder

Step5. Do some coding in that file

Sample code
import json print('Loading function') def lambda_handler(event, context): print("This is from Lambda ") return "Lambda Executed Successfully !"

Step7. Save the file

Step8.  Install boto3 modules for making python function ready

pip install boto3 -t ./

Step9. Make a ZIP package with correct file permissions



cd YOUR-FOLDER-NAME
chmod -R 755 .
zip -r ../myDeploymentPackage.zip .

Step10. Upload myDeploymentPackage.zip in Lambda using AWS portal or AWS CLI


  1. Open the AWS Lambda console.
  2. Choose Functions on the navigation pane, and then open your function.
  3. In the Function code section, expand the Code entry type drop-down list, and then choose Upload a .ZIP file.
  4. Choose Upload, and then select your .zip file.
  5. Choose Save.
  6. Choose Test.
You can also upload your .zip file from the AWS Command Line Interface (AWS CLI) using the update-function-code command.


Step11.  Make sure that you have proper settings


Handler should set as YOUR_FILE_NAME.YOUR_HANDLER_METHOD_NAME

For example

If you saved your file as "lambda_function.py" and the handler method is  "lambda_handler(event, context)" you should set "lambda_function.lambda_handler" as Handler in settings. Otherwise you will get error.


Same like step8 you can install any other modules for your code.


You are all set... All the best ! Happy Coding...!!