<?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>Forem: Prashanta Chakraborty</title>
    <description>The latest articles on Forem by Prashanta Chakraborty (@prashanta0234).</description>
    <link>https://forem.com/prashanta0234</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%2F1182779%2F2e4b2b4a-e4d5-49d5-a93d-eb3e8aa83940.jpg</url>
      <title>Forem: Prashanta Chakraborty</title>
      <link>https://forem.com/prashanta0234</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/prashanta0234"/>
    <language>en</language>
    <item>
      <title>Docker Port Exposing: My Real Production Mistake</title>
      <dc:creator>Prashanta Chakraborty</dc:creator>
      <pubDate>Sat, 21 Feb 2026 14:22:41 +0000</pubDate>
      <link>https://forem.com/prashanta0234/docker-port-exposing-my-real-production-mistake-4jd0</link>
      <guid>https://forem.com/prashanta0234/docker-port-exposing-my-real-production-mistake-4jd0</guid>
      <description>&lt;p&gt;I’m developing a Bangladesh-based healthcare system, &lt;a href="https://gooddoktor.com/" rel="noopener noreferrer"&gt;Gooddoktor&lt;/a&gt;.&lt;br&gt;
Recently, I deployed my backend in a VPS using Docker.&lt;/p&gt;

&lt;p&gt;I don’t have hardcore DevOps knowledge. I mostly:&lt;br&gt;
 &lt;strong&gt;learn → try → break → fix&lt;/strong&gt;. &lt;br&gt;
I set up nginx for the subdomain, all is ok. So yesterday I randomly tried a port scan on my own server. And guess what? I found multiple OPEN PORTS. Even worse…&lt;/p&gt;

&lt;p&gt;I could access my project using: &lt;code&gt;http://SERVER_IP:PORT&lt;/code&gt;. No domain, no SSL, Nothing. Anyone on the internet could directly access my services.&lt;/p&gt;

&lt;p&gt;My First Thought&lt;br&gt;
I asked ChatGPT: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;GPT gave firewall rules → I applied them → still accessible.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then I Googled → again firewall → again same result.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So clearly, the issue was not the firewall. That means something else was exposing the port.&lt;/p&gt;

&lt;p&gt;The Real Problem (Docker Did It)&lt;br&gt;
In my docker-compose I wrote:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ports:
 - "2525:2525"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks normal, right? But this line is VERY dangerous in production.&lt;/p&gt;

&lt;p&gt;What actually happens&lt;br&gt;
Docker doesn’t just run inside your machine. When you map a port like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2525:2525
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Docker tells Linux: Bind container port 2525 to ALL NETWORK INTERFACES, Meaning: &lt;code&gt;0.0.0.0:2525&lt;/code&gt; And &lt;code&gt;0.0.0.0&lt;/code&gt; means: Accept connections from anywhere in the world&lt;/p&gt;

&lt;p&gt;So the firewall allowed &lt;strong&gt;80&lt;/strong&gt; &amp;amp; &lt;strong&gt;443&lt;/strong&gt; only. But Docker bypassed it by opening its own socket. That’s why I could access:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;http://ip:2525&lt;/code&gt;&lt;br&gt;
Why the Firewall Didn’t Save Me&lt;br&gt;
Important lesson:&lt;/p&gt;

&lt;p&gt;Docker publishes ports BEFORE your firewall filtering in many cases (nat table). So, UFW rules ≠ protection if Docker exposes ports publicly. That’s why even after blocking, it still worked.&lt;/p&gt;

&lt;p&gt;The Fix (Actual Solution)&lt;br&gt;
Instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ports:
- "2525:2525"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I changed to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ports:
- "127.0.0.1:2525:2525"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now Docker binds to:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;127.0.0.1:2525&lt;/code&gt;&lt;br&gt;
Meaning:&lt;/p&gt;

&lt;p&gt;Only accessible from inside the server. Nginx can access. The Internet cannot. And boom. IP access stopped working.&lt;/p&gt;

&lt;p&gt;Why This Works&lt;/p&gt;

&lt;p&gt;Network scope difference:&lt;/p&gt;

&lt;p&gt;Binding: &lt;code&gt;0.0.0.0&lt;/code&gt;, Meaning: Public internet | Binding: &lt;code&gt;SERVER_IP&lt;/code&gt;, Meaning: Public internet | Binding: &lt;code&gt;127.0.0.1&lt;/code&gt;, Meaning: Only local machine&lt;/p&gt;

&lt;p&gt;So now the flow becomes:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;User → Domain → Nginx → localhost:2525 → Docker → App&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;User → Directly → Backend (very bad)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What I Learned&lt;/p&gt;

&lt;p&gt;Docker is not just a container; it’s a network gateway&lt;br&gt;
Port mapping is public by default&lt;br&gt;
A firewall alone cannot save a bad Docker config&lt;br&gt;
Production server should NEVER expose app ports&lt;br&gt;
Always expose only nginx (80/443)&lt;br&gt;
Final Advice&lt;/p&gt;

&lt;p&gt;If you’re deploying backend/services with Docker and nginx:&lt;/p&gt;

&lt;p&gt;Never do this in production&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ports:
- "3000:3000"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Always do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ports:
- "127.0.0.1:3000:3000"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Deployment is not coding…&lt;br&gt;
Deployment is security.&lt;/p&gt;

&lt;p&gt;And security mistakes don’t crash your app. They silently make your app public.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>devops</category>
      <category>docker</category>
    </item>
    <item>
      <title>Using Axios Instance with Interceptors in Redux Toolkit Query (RTK Query)</title>
      <dc:creator>Prashanta Chakraborty</dc:creator>
      <pubDate>Wed, 11 Oct 2023 21:18:16 +0000</pubDate>
      <link>https://forem.com/prashanta0234/using-axios-instance-with-interceptors-in-redux-toolkit-query-rtk-query-2jcl</link>
      <guid>https://forem.com/prashanta0234/using-axios-instance-with-interceptors-in-redux-toolkit-query-rtk-query-2jcl</guid>
      <description>&lt;p&gt;In this blog post, we'll walk through the process of setting up a Redux store that integrates a custom Axios instance with request and response interceptors, in addition to &lt;a href="https://redux-toolkit.js.org/introduction/getting-started"&gt;Redux Toolkit Query (RTK Query)&lt;/a&gt;. This comprehensive setup allows you to manage the state of your React application while efficiently handling API requests and responses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before we start, make sure you have the following prerequisites in place:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A React application set up and ready to integrate &lt;a href="https://redux-toolkit.js.org/introduction/getting-started"&gt;Redux&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://axios-http.com/docs/intro"&gt;Axios&lt;/a&gt; installed in your project. You can install Axios via npm or yarn:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install axios
# or
yarn add axios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Creating a Custom Axios Instance&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, let's create a custom &lt;a href="https://axios-http.com/docs/instance"&gt;Axios instance&lt;/a&gt; with request and response &lt;a href="https://axios-http.com/docs/interceptors"&gt;interceptors&lt;/a&gt;. This will give you the flexibility to modify requests and responses globally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// axiosInstance.js

import axios from 'axios';

const axiosInstance = axios.create({
  baseURL: 'https://api.example.com', // Replace with your API base URL
  headers: {
    'Content-Type': 'application/json',
    // Add any other headers or configurations you need
  },
});

// Add a request interceptor
axiosInstance.interceptors.request.use(
  (config) =&amp;gt; {
    // You can modify the request config here, e.g., add authentication headers
    // config.headers.Authorization = `Bearer ${getToken()}`;
    return config;
  },
  (error) =&amp;gt; {
    return Promise.reject(error);
  }
);

// Add a response interceptor
axiosInstance.interceptors.response.use(
  (response) =&amp;gt; {
    // You can modify the response data here, e.g., handling pagination
    return response.data;
  },
  (error) =&amp;gt; {
    return Promise.reject(error);
  }
);

export default axiosInstance;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We've created a custom Axios instance that includes both request and response interceptors, giving you full control over the communication with your API.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Setting up the Redux Store&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next, let's set up the Redux store to work in conjunction with Redux Toolkit Query. Ensure you have Redux and RTK Query installed in your project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @reduxjs/toolkit react-redux
# or
yarn add @reduxjs/toolkit react-redux

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's how you can set up your Redux store with RTK Query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// store.js

import { configureStore } from '@reduxjs/toolkit';
import { api } from './api'; // Import your RTK Query API

const store = configureStore({
  reducer: {
    [api.reducerPath]: api.reducer,
  },
  middleware: (getDefaultMiddleware) =&amp;gt;
    getDefaultMiddleware().concat(api.middleware),
});

export default store;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this store setup:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We import the &lt;strong&gt;api&lt;/strong&gt; object generated by RTK Query.&lt;/li&gt;
&lt;li&gt;The API reducer and middleware are integrated into the Redux store configuration.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Integrating RTK Query with the Custom Axios Instance&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With your Redux store in place, you can integrate RTK Query with the custom Axios instance. This is the same step we covered in the previous sections.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// api.js

import { createApi } from '@reduxjs/toolkit/query'
import axiosInstance from './axios'

const axiosBaseQuery =
  ({ baseUrl } = { baseUrl: '' }) =&amp;gt;
  async ({ url, method, data, params, headers }) =&amp;gt; {
    try {
      const result = await axiosInstance({
        url: baseUrl + url,
        method,
        data,
        params,
        headers,
      })
      return { data: result.data }
    } catch (axiosError) {
      const err = axiosError
      return {
        error: {
          status: err.response?.status,
          data: err.response?.data || err.message,
        },
      }
    }
  }

const api = createApi({
  baseQuery: axiosBaseQuery({
    baseUrl: 'https://example.com',
  }),
  endpoints(build) {
    return {
      query: build.query({ query: () =&amp;gt; ({ url: '/query', method: 'get' }) }),
      mutation: build.mutation({
        query: () =&amp;gt; ({ url: '/mutation', method: 'post' }),
      }),
    }
  },
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this step, we're integrating RTK Query with the custom Axios instance, as explained in previous sections.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using the Redux Store and RTK Query&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Finally, you can use the Redux store and RTK Query in your React components to manage state and make API requests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// MyComponent.js

import React from 'react';
import { useGetResourceQuery, useCreateResourceMutation } from './api'; // Import the generated hooks

function MyComponent() {
  const { data, error, isLoading } = useGetResourceQuery(1); // Replace 1 with the resource ID you want to fetch

  const [createResource] = useCreateResourceMutation();

  // Use createResource function to create a new resource

  return (
    &amp;lt;div&amp;gt;
      {/* Render your component based on the API data and loading/error states */}
    &amp;lt;/div&amp;gt;
  );
}

export default MyComponent;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By following these steps, you've set up a Redux store with a custom Axios instance that includes request and response interceptors. You've also integrated RTK Query for efficient state management and API communication in your React application. This combination offers control, flexibility, and convenience for managing your application's data.&lt;/p&gt;

&lt;p&gt;That's it! You've now set up a Redux store with a custom Axios instance and integrated it with RTK Query to manage state and API requests in your React application. This approach allows you to have full control over the Axios instance and API interactions while leveraging the benefits of Redux and RTK Query for state management.&lt;/p&gt;

&lt;p&gt;Follow Me on:&lt;br&gt;
&lt;a href="https://www.facebook.com/prashanta.chakraborty.14"&gt;facebook&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/prashanta-chakraborty/"&gt;linkedin&lt;/a&gt;&lt;/p&gt;

</description>
      <category>redux</category>
      <category>rtk</category>
      <category>react</category>
      <category>axios</category>
    </item>
  </channel>
</rss>
