Docker ip static with an existing container - docker

I have a problem with my docker container. I have a mongodb container that I can't stop, change ip or anything like that, but it's ip is not static and I have to set it static.
I tried creating a network with the same ip but it gives me this error:
Error response from daemon: Pool overlaps with other one on this address space
Is there anyway I can set my ip static without stopping or changing my container ip or starting over?

Related

Make the DNS server of docker container another docker container running DNSmasq

I have a set of docker containers created with docker compose, which creates a "user-defined" bridge network.
One of these docker containers is running DNSmasq so we can define custom (internal) domain names to point to local IPs.
Trouble is, none of the other docker containers can resolve these domain names. I think the issue is that I can't get the docker DNS to forward its requests to the docker container running DNSmasq (i.e. it doesn't even know it exists).
As a test, I did a docker network inspect <network created by docker compose> and noted the IP address of the DNSmasq container. Then, in one of the other containers' /etc/resolv.conf, I set nameserver to that IP address. Then I can resolve all these internal domains names.
Sadly, putting dnsmasq in there doesn't work, despite the fact that the user-defined network has automatic service discovery enabled.
It seems that one way to make this work then is to force my DNSmasq container to always have the same IP, and then make sure the other docker containers point to that as their nameserver, e.g. by defining the network explicitly in the compose file.
Is there no other way? I'd rather not have to define the entire network to replicate this automatically created one when all I want is to know the IP address of one container.

Docker containers that are not running on localhost

For regular docker containers (say the hello world example), after you run it, it is accessible thought localhost, where you can make a request it through your browser.
But sometimes it seems to access a container you need a special IP address. I'm wondering what's this behavior of docker container networking called and where is it defined/documented.
Let's say my local ip address is 10.0.75.1 (got from Network properties in Windows settings named, vEthernet (DockerNAT)). But in order to connect to a container running I had to use ip address 10.0.75.2. Why is this?
If try to inspect existing docker networks using docker network [cmd], the containers seem to be on different subnets, for example '172.17.0.0/16'

Docker Compose with static public IP over LAN but different with Host IP

I have the requirement where I need to expose all my containers through a static public IP.
However, the static public IP cannot be host IP because host IP must be dynamic.
The 2 solutions I found is macvlan and linux secondary IP, but base on my understanding, they cannot fulfil my need.
with macvlan, each container will get individual IP. I need to access all container through the same IP.
with linux secondary IP, I can assign a single static IP which exclusive for my docker container. However, I didn't found a way to manage the /etc/network/interface inside a docker container.
My question is:
Is it possible to set all container using same ip using macvlan?
Is there any way to manage/etc/network/interface, include ifup and ifdown inside a docker container?
Is there any alternative method
Edit:
the image is the system design for what I wish to achieve:
Assign the static IP to your host and use the ordinary docker run -p option. The host is allowed to have multiple IP addresses (it presumably already has its dynamic IP address and the Docker-internal 172.17.0.1 address) and you can use an additional parameter to docker run -p 10.10.10.10:80:8888 to bind to a specific host address (that specific address and no other, port 80, forwards to port 8888 in the container).
Another good setup is to provision a load balancer of some sort, assign the static IP address to it, and have it forward to the host. This is also helpful if you want to put some level of rate-limiting or basic HTTP filtering at this layer.
There's no specific technical barrier to running ifconfig by hand inside a container, but no off-the-shelf images expects to need to do it, which means you'll need to write all of your own images that won't really be reusable outside this specific environment. A developer might have trouble running the identical image locally, for instance.

Reload docker stack network configuration

I have multiple docker stacks that are connected over the same network. If I restart one of the stacks the internal ip addresses of the related stack container seems to change. That results in wrong service name resolutions in other stacks and containers. It seems that the internal docker name service doesn't recognize the network change.
If try to access other containers with ping from a stack container shell by the service name (for example ping my_stack_my_container_name) I got a successful return from a wrong IP address. When I use the full container name instead (ping my_stack_my_container_name.134.134234234123) the return comes from the right IP.
Is there any way to trigger a reload of the stack networking/name service?
are you sure it's not reloaded? check if the docker containers (that should connect to reloaded container) are not caching DNS query results. I had same issue in haproxy config and I placed following lines to force haproxy to hold values only for 1s:
resolvers docker
# well known docker dns server address
nameserver dns 127.0.0.11:53
#HAProxy will hold name-ip mapping for 1s, so for each request new container ip will be resolved, balancing load
hold valid 1s
(...)
backend stackName_app_backend
server stackName_app_service stackName_ServiceName:80 resolvers docker check

Is it possible to assign a static IP address to a docker container after it's creation?

Is it possible to assign a static IP address and hostname to a docker container after it's creation ?
All my container are in the same network (bridge). The docker IP 172.17.0.x assigned by bridge network to my containers change some time after a restart of docker service and I need a static IP to save the communication between container.
Another idea is to associate hostname to container. IP address is not static.
Here a simple way to use docker network to add hostname to existing container.
[link] https://stackoverflow.com/a/41298050/6288254

Resources