Tuesday, April 18, 2023

Setup Docker Engine on Windows using WSL2

Steps to setup docker on Windows 10/11 system without installing Docker Desktop application, which is just a GUI for docker.

First, you need to install WSL (Windows subsystem for Linux) if not already installed -

wsl --install

Note: It will install ubuntu linux as default linux flavour. If you need to check and install any other use below command:

        wsl --list --online

        wsl --install kali-linux

Next, install docker using below commands

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

          sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Last, verify docker is installed and running successfully.

        docker run hello-world

        docker run docker/getting-started

Verify all processes running on ubuntu machine.



Finally, to view and setup getting-started with docker code, download and install git using :

    sudo apt-get install git


Ref - https://medium.com/geekculture/run-docker-in-windows-10-11-wsl-without-docker-desktop-a2a7eb90556d

Ref - https://docs.docker.com/engine/install/ubuntu/#installation-methods

Monday, April 10, 2023

Setup MongoDB on Docker

Setup MongoDB community server as a single node.

$ docker pull mongodb/mongodb-community-server











Verify MongoDB image is downloaded successfully: 

$ docker images



Run docker image

$ docker run --name mongo -p 27017:27017 -d mongodb/mongodb-community-server:latest


Setup MongoDB 3 node cluster on docker

The steps to create a docker cluster are as follows.

  1. Create a Docker network.
            $ docker network create mongoCluster
  1. Start three instances of MongoDB.
docker run -d --rm -p 27017:27017 --name mongo1 --network mongoCluster mongo mongod --replSet myReplicaSet --bind_ip localhost,mongo1

docker run -d --rm -p 27018:27017 --name mongo2 --network mongoCluster mongo mongod --replSet myReplicaSet --bind_ip localhost,mongo2
 
docker run -d --rm -p 27019:27017 --name mongo3 --network mongoCluster mongo mongod --replSet myReplicaSet --bind_ip localhost,mongo3

  1. Initiate the Replica Set.
docker exec -it mongo1 mongosh --eval "rs.initiate({
 _id: \"myReplicaSet\",
 members: [
   {_id: 0, host: \"mongo1\"},
   {_id: 1, host: \"mongo2\"},
   {_id: 2, host: \"mongo3\"}
 ]
})"

docker exec -it mongo1 mongosh --eval "rs.status()"

Detailed information on Replica set configuration can be found here.

Once you have a MongoDB cluster up and running, you will be able to experiment with it.

Ref: https://www.mongodb.com/compatibility/deploying-a-mongodb-cluster-with-docker


Using Docker Compose -

docker-compose -f config/docker-compose.yaml up -d


More details on cluster setup can be learned from Mongodb University here.

Cybersecurity Essential: OpenSSL

In today’s digital landscape, securing data is paramount. Whether you’re building web applications, managing servers, or developing software...