VOOZH about

URL: https://www.geeksforgeeks.org/devops/how-to-provide-the-static-ip-to-a-docker-container/

⇱ How to Provide the Static IP to a Docker Container? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Provide the Static IP to a Docker Container?

Last Updated : 4 Jan, 2025

Docker is an open-source project that makes it easier to create, deploy and run applications. It provides a lightweight environment to run your applications.
It is a tool that makes an isolated environment inside your computer. Think of Docker as your private room in your house. Living with your family, you have to share a TV, table, chair and so on. Once you get into your room, all are yours. You don't have to share them, and feel private, though your family may listen to your voice and tell you to be calm. Docker is like your room. Docker can be private from the host computer, though in some parts it is monitored and controlled by the host.

Let's Come to Our Problem statement: We Want to Create aDocker Container with Static IP.

Let's Say We have configured our Server and Connected with CICD tools which Update the Application and Relaunch our Complete Docker Environment But as the New Environment is Created Which lead to change the IP definitely But Our Use Case is that We Don't Want to Change Because Might be that some other application depends on it and if the IP changed then that application Stop Working.

Solution:

Step 1: Configure the Docker in the Server

👁 Image
Installation of Docker
👁 Image
Pulling the Latest Nginx Image


👁 Image
Show the Images

Step 2:  Create a Network with Subnet (CIDR).

👁 Image
Creating Network 
👁 Image
List the Network

Step 3: Deploy the Container this Network with your Custom Static IP

  • Specify: 
    • Network Name (Which You at the time of Creation Of Network)
    • Specify the IP (Which is Under that Network)

👁 Image
Inspect Container And Check the Network


Output:

👁 Image
Container with Static IP Address
Comment