Thursday 22 June 2023

How to change the docker default gateway and ip?

ref: chatgpt

To change the gateway IP address for an NGINX Docker container, you can make use of Docker's network functionality. Follow these steps:

  1. Find the name or ID of the Docker network associated with your NGINX container. You can use the docker network ls command to list the available networks and identify the one that your container is connected to.

  2. Use the docker network inspect command to retrieve detailed information about the network. Replace <network-name> with the name or ID of the network from the previous step. For example:

    • docker network inspect <network-name>
  3. Look for the "Containers" section in the output of the docker network inspect command. Find the entry that corresponds to your NGINX container. Note down the "Container ID" value.
  4. Stop the NGINX container using the docker stop command. Replace <container-id> with the Container ID obtained in the previous step:
    • docker stop <container-id>
  5. Disconnect the NGINX container from the network using the docker network disconnect command. Replace <network-name> and <container-id> with the appropriate values:
    • docker network disconnect <network-name> <container-id>
  6. Create a new network with the desired gateway IP address using the docker network create command. Replace <new-network-name> and <new-gateway-ip> with your desired values:
    • docker network create --subnet=<new-gateway-ip>/16 --gateway=<new-gateway-ip> <new-network-name>
  7. Reconnect the NGINX container to the new network using the docker network connect command. Replace <new-network-name> and <container-id> with the appropriate values: 
    • docker network connect <new-network-name> <container-id>
  8. Start the NGINX container again:
    • docker start <container-id>

After following these steps, your NGINX container should be connected to the new network with the specified gateway IP address. Please note that this approach assumes you have administrative privileges and sufficient Docker knowledge to manage networks and containers.

No comments:

Post a Comment