<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ferdous Azad</title>
    <description>The latest articles on DEV Community by Ferdous Azad (@ferdousazad).</description>
    <link>https://dev.to/ferdousazad</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1600738%2F8a175ced-a96a-4917-8180-b6770554c1ab.jpg</url>
      <title>DEV Community: Ferdous Azad</title>
      <link>https://dev.to/ferdousazad</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ferdousazad"/>
    <language>en</language>
    <item>
      <title>A beginners guide to Kubernetes with Docker</title>
      <dc:creator>Ferdous Azad</dc:creator>
      <pubDate>Sun, 16 Jun 2024 15:31:42 +0000</pubDate>
      <link>https://dev.to/ferdousazad/a-beginners-guide-to-kubernetes-with-docker-1e4m</link>
      <guid>https://dev.to/ferdousazad/a-beginners-guide-to-kubernetes-with-docker-1e4m</guid>
      <description>&lt;p&gt;&lt;strong&gt;Kubernetes&lt;/strong&gt; (often abbreviated as K8s) is an open-source platform for automating the deployment, scaling, and operation of application containers. It works with various container runtimes, including Docker, to orchestrate containerized applications across clusters of machines.&lt;/p&gt;

&lt;p&gt;Here’s a brief tutorial on Kubernetes and how it works with Docker containers:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Basic Concepts in Kubernetes&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cluster:&lt;/strong&gt; A set of nodes (machines) running containerized applications managed by Kubernetes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Node:&lt;/strong&gt;A single machine in a Kubernetes cluster. It can be a physical or virtual machine.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pod:&lt;/strong&gt; The smallest deployable unit in Kubernetes, which can contain one or more containers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Service:&lt;/strong&gt;*An abstraction that defines a logical set of pods and a policy by which to access them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deployment:&lt;/strong&gt; Manages a set of identical pods, ensuring the correct number of replicas and allowing updates.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ConfigMap and Secret:&lt;/strong&gt;Objects for managing configuration data and sensitive information, respectively.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Installing Kubernetes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can install Kubernetes locally using tools like Minikube or kind (Kubernetes in Docker). For production, you’d typically use a cloud provider’s managed Kubernetes service, such as GKE (Google Kubernetes Engine), EKS (Amazon Elastic Kubernetes Service), or AKS (Azure Kubernetes Service).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install Minikube&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Follow the installation guide for your operating system on the &lt;a href="https://minikube.sigs.k8s.io/docs/start/"&gt;Minikube website&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Start Minikube:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;minikube start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install kubectl:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Follow the installation guide on the Kubernetes &lt;a href="https://kubernetes.io/"&gt;website&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Creating a Simple Kubernetes Application&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Step 1: Create a Deployment&lt;/p&gt;

&lt;p&gt;Create a Docker image:&lt;br&gt;
Dockerfile:&lt;/p&gt;

&lt;p&gt;`FROM node:14&lt;/p&gt;

&lt;p&gt;WORKDIR /usr/src/app&lt;/p&gt;

&lt;p&gt;COPY package*.json ./&lt;/p&gt;

&lt;p&gt;RUN npm install&lt;/p&gt;

&lt;p&gt;COPY . .&lt;/p&gt;

&lt;p&gt;EXPOSE 3000&lt;/p&gt;

&lt;p&gt;CMD ["node", "app.js"]`&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Build the Docker image:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;docker build -t node-app:latest .&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Push the image to a container registry (e.g., Docker Hub):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker tag node-app:latest &amp;lt;your-dockerhub-username&amp;gt;/node-app:latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker push &amp;lt;your-dockerhub-username&amp;gt;/node-app:latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create a Kubernetes Deployment YAML file (&lt;code&gt;deployment.yaml&lt;/code&gt;):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: apps/v1
kind: Deployment
metadata:
  name: node-app-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: node-app
  template:
    metadata:
      labels:
        app: node-app
    spec:
      containers:
      - name: node-app
        image: &amp;lt;your-dockerhub-username&amp;gt;/node-app:latest
        ports:
        - containerPort: 3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apply the deployment:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;kubectl apply -f deployment.yaml&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check the deployment and pods:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get deployments
kubectl get pods
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2: Create a Service&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create a Service YAML file (&lt;code&gt;service.yaml&lt;/code&gt;):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: v1
kind: Service
metadata:
  name: node-app-service
spec:
  selector:
    app: node-app
  ports:
  - protocol: TCP
    port: 80
    targetPort: 3000
  type: LoadBalancer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Apply the service:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;kubectl apply -f service.yaml&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Check the service:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;kubectl get services&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Access the application:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Use the external IP provided by the service (in Minikube, use &lt;code&gt;minikube service node-app-service – url&lt;/code&gt;).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Communicating Between Services&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;step 1: Set Up a Database Service&lt;/p&gt;

&lt;p&gt;Create a PostgreSQL Deployment and Service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
      - name: postgres
        image: postgres:latest
        env:
        - name: POSTGRES_DB
          value: mydatabase
        - name: POSTGRES_USER
          value: postgres
        - name: POSTGRES_PASSWORD
          value: mysecretpassword
        ports:
        - containerPort: 5432

---
apiVersion: v1
kind: Service
metadata:
  name: postgres-service
spec:
  selector:
    app: postgres
  ports:
  - protocol: TCP
    port: 5432
    targetPort: 5432
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Apply the deployment and service:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;kubectl apply -f postgres.yaml&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Step 2: Update Node.js Application to Use Database&lt;/p&gt;

&lt;p&gt;Modify &lt;code&gt;app.js&lt;/code&gt; to connect to PostgreSQL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const { Pool } = require('pg');
const app = express();
const PORT = 3000;

const pool = new Pool({
  user: 'postgres',
  host: 'postgres-service',
  database: 'mydatabase',
  password: 'mysecretpassword',
  port: 5432,
});

app.get('/', async (req, res) =&amp;gt; {
  const result = await pool.query('SELECT NOW()');
  res.send(`PostgreSQL time: ${result.rows[0].now}`);
});

app.listen(PORT, () =&amp;gt; {
  console.log(`Server is running on port ${PORT}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Build and push the updated Docker image:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -t &amp;lt;your-dockerhub-username&amp;gt;/node-app:latest .
docker push &amp;lt;your-dockerhub-username&amp;gt;/node-app:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Update the deployment:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;kubectl set image deployment/node-app-deployment node-app=&amp;lt;your-dockerhub-username&amp;gt;/node-app:latest&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Scaling and Updating Applications&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Scale the deployment:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;kubectl scale deployment node-app-deployment – replicas=5&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Update the deployment with a new image:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;kubectl set image deployment/node-app-deployment node-app=&amp;lt;your-dockerhub-username&amp;gt;/node-app:new-version&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Managing Configurations with ConfigMaps and Secrets&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Create a ConfigMap:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;configmap.yaml&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  DATABASE_HOST: postgres-service
  DATABASE_USER: postgres
  DATABASE_PASSWORD: mysecretpassword
  DATABASE_NAME: mydatabase
Applying the ConfigMap:

kubectl apply -f configmap.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: node-app-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: node-app
  template:
    metadata:
      labels:
        app: node-app
    spec:
      containers:
      - name: node-app
        image: &amp;lt;your-dockerhub-username&amp;gt;/node-app:latest
        ports:
        - containerPort: 3000
        env:
        - name: DATABASE_HOST
          valueFrom:
            configMapKeyRef:
              name: app-config
              key: DATABASE_HOST
        - name: DATABASE_USER
          valueFrom:
            configMapKeyRef:
              name: app-config
              key: DATABASE_USER
        - name: DATABASE_PASSWORD
          valueFrom:
            configMapKeyRef:
              name: app-config
              key: DATABASE_PASSWORD
        - name: DATABASE_NAME
          valueFrom:
            configMapKeyRef:
              name: app-config
              key: DATABASE_NAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure to replace  with your actual Docker Hub username.&lt;/p&gt;

&lt;p&gt;The ConfigMap provides database configuration information that the node-app container in the Deployment uses through environment variables. The kubectl apply -f configmap.yaml command applies the ConfigMap configuration to your Kubernetes cluster.&lt;/p&gt;

&lt;p&gt;This tutorial covers the basics of Kubernetes, deploying and managing Docker containers, and communicating between services. For more advanced topics, consider exploring Kubernetes documentation and other resources.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>docker</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Docker a beginners guide</title>
      <dc:creator>Ferdous Azad</dc:creator>
      <pubDate>Sun, 16 Jun 2024 15:15:36 +0000</pubDate>
      <link>https://dev.to/ferdousazad/docker-a-beginners-guide-ea3</link>
      <guid>https://dev.to/ferdousazad/docker-a-beginners-guide-ea3</guid>
      <description>&lt;p&gt;Docker is a platform for developing, shipping, and running applications in containers. Containers are lightweight and contain everything needed to run an application, making them portable and consistent across environments.&lt;/p&gt;

&lt;p&gt;Here’s a brief tutorial on Docker, including creating containers, networking between containers, and setting up a simple multi-container application involving a database, cache, and services written in Node.js and Go.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;1. Install Docker&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Install Docker from Docker’s official &lt;a href="https://www.docker.com/"&gt;website&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;2. Basic Docker Commands&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Pull an image:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker pull &amp;lt;image-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker pull node:14&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Run a container:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker run -d – name &amp;lt;container-name&amp;gt; &amp;lt;image-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker run -d – name my-node-container node:14&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;List running containers:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker ps&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stop a container:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker stop &amp;lt;container-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remove a container:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker rm &amp;lt;container-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;3. Creating a Node.js Application Container&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Create a simple Node.js application:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir node-app
cd node-app
npm init -y
npm install express
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Create &lt;code&gt;app.js&lt;/code&gt;:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require(‘express’);
const app = express();
const PORT = 3000;

app.get('/', (req, res) =&amp;gt; {
  res.send('Hello from Node.js!');
});

app.listen(PORT, () =&amp;gt; {
  console.log(`Server is running on port ${PORT}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;3. Create `Dockerfile:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Dockerfile&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
FROM node:14&lt;/p&gt;

&lt;p&gt;WORKDIR /usr/src/app&lt;/p&gt;

&lt;p&gt;COPY package.json ./&lt;/p&gt;

&lt;p&gt;RUN npm install&lt;/p&gt;

&lt;p&gt;COPY . .&lt;/p&gt;

&lt;p&gt;EXPOSE 3000&lt;/p&gt;

&lt;p&gt;CMD ["node", "app.js"]&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;4. Build the Docker image:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;docker build -t node-app .&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;5. Run the container:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;docker run -d – name node-app-container -p 3000:3000 node-app&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating a Go Application Container&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create a simple Go application:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
mkdir go-app&lt;br&gt;
cd go-app&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Create &lt;code&gt;main.go&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
package main&lt;/p&gt;

&lt;p&gt;import (&lt;br&gt;
  "fmt"&lt;br&gt;
  "net/http"&lt;br&gt;
)&lt;/p&gt;

&lt;p&gt;func handler(w http.ResponseWriter, r *http.Request) {&lt;br&gt;
    fmt.Fprintf(w, "Hello from Go!")&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;func main() {&lt;br&gt;
  http.HandleFunc("/", handler)&lt;br&gt;
  http.ListenAndServe(":8080", nil)&lt;br&gt;
}&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Create &lt;code&gt;Dockerfile&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Dockerfile&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
FROM golang:1.16&lt;/p&gt;

&lt;p&gt;WORKDIR /app&lt;/p&gt;

&lt;p&gt;COPY . .&lt;/p&gt;

&lt;p&gt;RUN go build -o main .&lt;/p&gt;

&lt;p&gt;EXPOSE 8080&lt;/p&gt;

&lt;p&gt;CMD ["./main"]&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Build the Docker image:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker build -t go-app .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Run the container:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker run -d – name go-app-container -p 8080:8080 go-app&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Setting Up a Database Container&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Run a PostgreSQL container:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
docker run -d – name postgres-container -e POSTGRES_PASSWORD=mysecretpassword -e POSTGRES_DB=mydatabase -p 5432:5432 postgres&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Setting Up a Redis Cache Container&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Run a Redis container:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;docker run -d – name redis-container -p 6379:6379 redis&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Networking Between Containers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Docker provides several ways to network containers. The simplest way is to use Docker’s default bridge network.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create a custom network:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker network create my-network&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Run containers in the same network:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
docker run -d – name postgres-container – network my-network -e POSTGRES_PASSWORD=mysecretpassword -e POSTGRES_DB=mydatabase postgres&lt;br&gt;
docker run -d – name redis-container – network my-network redis&lt;br&gt;
docker run -d – name node-app-container – network my-network -p 3000:3000 node-app&lt;br&gt;
docker run -d – name go-app-container – network my-network -p 8080:8080 go-app&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Connecting Services to Database and Cache&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Example Node.js (app.js) connecting to PostgreSQL and Redis:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install dependencies:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install pg redis&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Modify &lt;code&gt;app.js&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
const express = require('express');&lt;br&gt;
const { Pool } = require('pg');&lt;br&gt;
const redis = require('redis');&lt;br&gt;
const app = express();&lt;br&gt;
const PORT = 3000;&lt;br&gt;
const pool = new Pool({&lt;br&gt;
  user: 'postgres',&lt;br&gt;
  host: 'postgres-container',&lt;br&gt;
  database: 'mydatabase',&lt;br&gt;
  password: 'mysecretpassword',&lt;br&gt;
  port: 5432,&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;const client = redis.createClient({&lt;br&gt;
  host: 'redis-container',&lt;br&gt;
  port: 6379,&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;app.get('/', async (req, res) =&amp;gt; {&lt;br&gt;
  const result = await pool.query('SELECT NOW()');&lt;/p&gt;

&lt;p&gt;client.set('key', 'value');&lt;/p&gt;

&lt;p&gt;client.get('key', (err, value) =&amp;gt; {&lt;br&gt;
     res.send(&lt;code&gt;PostgreSQL time: ${result.rows[0].now}, Redis value: ${value}&lt;/code&gt;);&lt;br&gt;
  });&lt;/p&gt;

&lt;p&gt;});&lt;/p&gt;

&lt;p&gt;app.listen(PORT, () =&amp;gt; {&lt;br&gt;
  console.log(&lt;code&gt;Server is running on port ${PORT}&lt;/code&gt;);&lt;br&gt;
});&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Example Go (&lt;code&gt;main.go&lt;/code&gt;) connecting to PostgreSQL and Redis:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install dependencies:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;go get github.com/lib/pq&lt;br&gt;
go get github.com/go-redis/redis/v8&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Modify &lt;code&gt;main.go&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
package main&lt;/p&gt;

&lt;p&gt;import (&lt;br&gt;
  "context"&lt;br&gt;
  "database/sql"&lt;br&gt;
  "fmt"&lt;br&gt;
  "net/http"&lt;br&gt;
  "github.com/go-redis/redis/v8"&lt;br&gt;
  _ "github.com/lib/pq"&lt;br&gt;
)&lt;/p&gt;

&lt;p&gt;var ctx = context.Background()&lt;/p&gt;

&lt;p&gt;func handler(w http.ResponseWriter, r *http.Request) {&lt;br&gt;
  connStr := "user=postgres password=mysecretpassword dbname=mydatabase host=postgres-container sslmode=disable"&lt;br&gt;
  db, err := sql.Open("postgres", connStr)&lt;/p&gt;

&lt;p&gt;if err != nil {&lt;br&gt;
    panic(err)&lt;br&gt;
  }&lt;/p&gt;

&lt;p&gt;defer db.Close()&lt;/p&gt;

&lt;p&gt;var now string&lt;br&gt;
  err = db.QueryRow("SELECT NOW()").Scan(&amp;amp;now)&lt;/p&gt;

&lt;p&gt;if err != nil {&lt;br&gt;
    panic(err)&lt;br&gt;
  }&lt;/p&gt;

&lt;p&gt;rdb := redis.NewClient(&amp;amp;redis.Options{&lt;br&gt;
    Addr: "redis-container:6379",&lt;br&gt;
  })&lt;/p&gt;

&lt;p&gt;err = rdb.Set(ctx, "key", "value", 0).Err()&lt;/p&gt;

&lt;p&gt;if err != nil {&lt;br&gt;
  panic(err)&lt;br&gt;
  }&lt;/p&gt;

&lt;p&gt;val, err := rdb.Get(ctx, "key").Result()&lt;/p&gt;

&lt;p&gt;if err != nil {&lt;br&gt;
    panic(err)&lt;br&gt;
  }&lt;/p&gt;

&lt;p&gt;fmt.Fprintf(w, "PostgreSQL time: %s, Redis value: %s", now, val)&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;func main() {&lt;br&gt;
  http.HandleFunc("/", handler)&lt;br&gt;
  http.ListenAndServe(":8080", nil)&lt;br&gt;
}&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;9. Docker Compose&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To simplify the process, you can use Docker Compose to define and run multi-container Docker applications.&lt;/p&gt;

&lt;p&gt;Create &lt;code&gt;docker-compose.yml&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
version: '3'&lt;/p&gt;

&lt;p&gt;services:&lt;br&gt;
  postgres:&lt;br&gt;
    image: postgres&lt;br&gt;
    environment:&lt;br&gt;
      POSTGRES_PASSWORD: mysecretpassword&lt;br&gt;
      POSTGRES_DB: mydatabase&lt;br&gt;
    networks:&lt;br&gt;
      - my-network&lt;/p&gt;

&lt;p&gt;redis:&lt;br&gt;
    image: redis&lt;br&gt;
    networks:&lt;br&gt;
      - my-network&lt;/p&gt;

&lt;p&gt;node-app:&lt;br&gt;
    build: ./node-app&lt;br&gt;
    ports:&lt;br&gt;
      - "3000:3000"&lt;br&gt;
    networks:&lt;br&gt;
      - my-network&lt;/p&gt;

&lt;p&gt;go-app:&lt;br&gt;
    build: ./go-app&lt;br&gt;
    ports:&lt;br&gt;
      - "8080:8080"&lt;br&gt;
    networks:&lt;br&gt;
      - my-network&lt;/p&gt;

&lt;p&gt;networks:&lt;br&gt;
  my-network:&lt;br&gt;
    driver: bridge&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Run the application:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker-compose up – build&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;By following this tutorial, you can set up a multi-container application with Docker, including networking between containers and connecting services to a database and cache.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>node</category>
    </item>
    <item>
      <title>Open Web Application Security Project OWASP Top Ten</title>
      <dc:creator>Ferdous Azad</dc:creator>
      <pubDate>Sun, 16 Jun 2024 14:56:08 +0000</pubDate>
      <link>https://dev.to/ferdousazad/open-web-application-security-project-owasp-top-ten-l7o</link>
      <guid>https://dev.to/ferdousazad/open-web-application-security-project-owasp-top-ten-l7o</guid>
      <description>&lt;p&gt;Web security is crucial for protecting applications and data from various threats. The OWASP (Open Web Application Security Project) Top Ten is a widely recognized list of the most critical web application security risks. Here’s a detailed explanation of common web security best practices, including those highlighted by the OWASP Top Ten:&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;1. Injection (OWASP A1)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br&gt;
Injection flaws, such as SQL, NoSQL, OS, and LDAP injection, occur when untrusted data is sent to an interpreter as part of a command or query. The attacker’s hostile data can trick the interpreter into executing unintended commands or accessing unauthorized data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best Practices:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Use parameterized queries and prepared statements.&lt;br&gt;
Employ ORM (Object-Relational Mapping) libraries that provide automatic query parameterization.&lt;br&gt;
Validate and sanitize all inputs.&lt;br&gt;
Use ORM and avoid dynamically constructing queries.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;2. Broken Authentication (OWASP A2)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br&gt;
This risk arises from incorrect implementation of authentication mechanisms, allowing attackers to compromise passwords, keys, or session tokens, or exploit other implementation flaws to assume other users’ identities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best Practices:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Implement multi-factor authentication (MFA).&lt;br&gt;
Ensure session tokens are properly secured.&lt;br&gt;
Use secure password storage methods (e.g., bcrypt).&lt;br&gt;
Implement account lockout mechanisms and ensure secure password recovery processes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Sensitive Data Exposure (OWASP A3)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br&gt;
**Sensitive data exposure occurs when applications do not adequately protect sensitive information such as credit cards, healthcare information, or personal identifiers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best Practices:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Use strong encryption for data at rest and in transit (e.g., TLS).&lt;br&gt;
Implement strict access controls.&lt;br&gt;
Avoid storing sensitive data unless absolutely necessary.&lt;br&gt;
Ensure that data is masked or encrypted when displayed.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;4. XML External Entities (XXE) (OWASP A4)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br&gt;
XXE vulnerabilities occur when XML input containing a reference to an external entity is processed by a weakly configured XML parser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best Practices:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Disable external entity processing in XML parsers.&lt;br&gt;
Use less complex data formats such as JSON, if possible.&lt;br&gt;
Validate and sanitize XML inputs.&lt;br&gt;
Regularly update XML parsers and libraries.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;5. Broken Access Control (OWASP A5)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br&gt;
Broken access control vulnerabilities arise when users are able to act outside of their intended permissions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best Practices:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Enforce least privilege: only give users access to what they need.&lt;br&gt;
Implement role-based access control (RBAC).&lt;br&gt;
Regularly review and test access controls.&lt;br&gt;
Use access control mechanisms provided by the platform (e.g., frameworks, libraries).&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;6. Security Misconfiguration (OWASP A6)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br&gt;
Security misconfigurations occur when security settings are defined, implemented, and maintained as insecure defaults or are incomplete and ad-hoc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best Practices:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Implement a repeatable hardening process.&lt;br&gt;
Regularly update and patch systems and software.&lt;br&gt;
Remove or disable unnecessary features and services.&lt;br&gt;
Apply security configurations across the entire software stack.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;7. Cross-Site Scripting (XSS) (OWASP A7)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br&gt;
XSS vulnerabilities occur when an application includes untrusted data in a new web page without proper validation or escaping, or updates an existing web page with user-supplied data using a browser API that can create HTML or JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best Practices:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Use frameworks that automatically escape XSS by design.&lt;br&gt;
Sanitize and validate input data.&lt;br&gt;
Use Content Security Policy (CSP) to prevent the execution of malicious scripts.&lt;br&gt;
Encode data on output.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;8. Insecure Deserialization (OWASP A8)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br&gt;
Insecure deserialization flaws occur when applications deserialize untrusted data, allowing attackers to execute arbitrary code or conduct injection attacks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best Practices:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Avoid deserializing data from untrusted sources.&lt;br&gt;
Implement integrity checks such as digital signatures on serialized objects.&lt;br&gt;
Use a safe and secure serialization mechanism.&lt;br&gt;
Restrict and monitor deserialization.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;9. Using Components with Known Vulnerabilities (OWASP A9)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br&gt;
Applications that use libraries, frameworks, and other software modules with known vulnerabilities can undermine application defenses and enable various attacks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best Practices:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Regularly update and patch dependencies.&lt;br&gt;
Use tools to scan for known vulnerabilities in dependencies.&lt;br&gt;
Subscribe to security bulletins related to the components you use.&lt;br&gt;
Prefer components that are actively maintained and have a strong security record.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;10. Insufficient Logging &amp;amp; Monitoring (OWASP A10)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br&gt;
Inadequate logging and monitoring, coupled with missing or ineffective integration with incident response, allows attackers to achieve their goals without being detected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best Practices:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Implement comprehensive logging of security-relevant events.&lt;br&gt;
Ensure logs are generated in a format that can be easily consumed by centralized log management solutions.&lt;br&gt;
Regularly monitor logs and establish an alerting mechanism for suspicious activities.&lt;br&gt;
Conduct regular audits and reviews of logs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Additional Best Practices:&lt;/strong&gt;&lt;br&gt;
Secure Development Practices: Follow secure coding standards and guidelines. Regularly train developers on security best practices.&lt;br&gt;
Threat Modeling: Perform threat modeling to identify and mitigate potential security threats during the design phase.&lt;/p&gt;

&lt;p&gt;Regular Security Testing: Conduct regular security testing, including code reviews, penetration testing, and automated security scans.&lt;br&gt;
Secure DevOps (DevSecOps): Integrate security practices into the DevOps pipeline to ensure continuous security throughout the development lifecycle.&lt;/p&gt;

&lt;p&gt;By implementing these best practices, you can significantly enhance the security of your web applications and protect them against common threats.&lt;/p&gt;

&lt;p&gt;Read More: &lt;a href="https://owasp.org/www-project-top-ten/"&gt;OWASP Top Ten&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>websecurity</category>
      <category>owasp</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
