Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get the IP adress to use for a docker container on a network

My NAS is where I run my containers. It sits on 192.168.1.23 on my network.

I am running a few containers inside a user-defined network. Here is the docker network inspect (I've removed the containers manually) :

[
    {
        "Name": "traefik2_proxy",
        "Id": "fb2924fe59fbb0436c72f11cb028df832a473a165162ecf08b7e3a946cfa2d3c",
        "Created": "2020-05-13T23:23:16.16424119+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "192.168.90.0/24",
                    "Gateway": "192.168.90.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]

I have a specific container which is in that network at IP address 192.168.90.16 for which I have exposed the 9118 port using the following in my docker-compose :

ports:
  - target: 9118
    published: 9118
    protocol: tcp

This is the portainer screenshot :

enter image description here

I was expecting to be able to connect to that container using 192.168.1.23:9118 but I tried to no avail.

What am I missing ? Which setting do I need to change for that container to be visible at that port on my NAS IP address ?

like image 302
Chapo Avatar asked May 15 '20 10:05

Chapo


People also ask

What IP address does a Docker container use?

Usually Docker uses the default 172.17. 0.0/16 subnet for container networking.

Does Docker container have same IP as host?

On Docker for Linux, the IP address of the gateway between the Docker host and the bridge network is 172.17. 0.1 if you are using default networking. Do you see the problem already? They are different, so you cannot simply run docker-compose up -d and all operating systems behave the same.

What is the default IP address of a docker container?

Docker Container IP Address By default, the container is assigned an IP address for every Docker network it connects to. And each network is created with a default subnet mask, using it as a pool later on to give away the IP addresses. Usually Docker uses the default 172.17. 0.0/16 subnet for container networking.

What is a docker network?

This network is called a "docker network". Think of docker network as a pool of available IP addresses. If two containers take on IP addresses from the same pool, they're going to be able to communicate with each other.

How do I connect a docker container to a bridge network?

Container IP addresses are an essential part of networking docker containers. Typically, containers are assigned an IP address for every network they connect. On the other hand, you can also manually connect a docker container to the bridge network using the command below. $ docker run -dt rabbitmq

How do Docker containers communicate with each other?

Think of docker network as a pool of available IP addresses. If two containers take on IP addresses from the same pool, they're going to be able to communicate with each other. There are mainly two types of networks, the default or predefined networks and the user-defined networks. Ignore the last two and focus on the first network.


1 Answers

The port that the container was listening to was incorrect. I needed to modify the ports configuration to:

ports: 
  - target: 9117 
    published: 9118 
    protocol: tcp
like image 93
Chapo Avatar answered Oct 05 '22 19:10

Chapo