Docker Community Forums

Share and learn in the Docker community.

Ipv4_address in docker-compose.yaml causing issues


(Dpearcefl) #1

I am trying to define a static IP in my docker-compose.yaml file just like is shown here: https://docs.docker.com/compose/compose-file/#/ipv4-address-ipv6-address

Here is my actual yaml file:

services:
  fred:
    image: dave:web1
    expose:
      - "80"
      - "22"
    ports:
      - "80"
      - "22"
    command: tail -f /dev/null
    networks:
      web_default:
        ipv4_address: 172.18.100.11

networks:
web_default:
driver: bridge
driver_opts:
com.docker.network.enable_ipv6: "false"
ipam:
driver: default
config:
- subnet: 172.18.0.0/24
gateway: 172.18.0.1

When I run docker-compse, I get this:

root@peter:~/docker/farming/web# docker-compose up -d
ERROR: Validation failed in file './docker-compose.yml', reason(s):
services.fred.networks contains an invalid type, it should be an array

Why?

root@peter:~/docker/farming/web# docker --version
Docker version 1.12.0, build 8eab29e
root@peter:~/docker/farming/web# docker-compose --version
docker-compose version 1.6.0, build d99cad6


(Dvohra) #2

Refer similar issues.




(Nathan Le Claire) #3

It seems like a bug in Compose since the documentation explicitly implies that a dictionary should be supported in this field as well as an array (https://docs.docker.com/compose/compose-file/#/ipv4-address-ipv6-address).

Try 1.8.0 (1.6.0 is your listed version here) to see if the issue still exists. If not, I recommend filing an issue at https://github.com/docker/compose/issues/new with a minimal reproducible example.


(Dpearcefl) #4

Switching to docker-compose 1.8.0 got the container to start. But the running container says this for the ports:
0.0.0.0:32781->22/tcp, 0.0.0.0:32780->80/tcp

It doesn’t seem to use what I listed.

Latest docker-compose.yml:
services:
fred:
image: dave:web1
expose:
- “80”
- "22"
ports:
- “80”
- "22"
command: tail -f /dev/null
networks:
app_net:
ipv4_address: 172.20.0.11
networks:
app_net:
driver: bridge
driver_opts:
com.docker.network.enable_ipv6: "false"
ipam:
driver: default
config:
- subnet: 172.20.0.0/24
gateway: 172.20.0.1


(Nathan Le Claire) #5

0.0.0.0 means “bind on all interfaces” so it may well be using that container IP just fine, the port output alone will not tell you which IP the container is using. If you check the container’s ip with docker inspect -f {{.NetworkSettings.IPAddress}} is it the expected IP?

BTW, why is it so important that you have a static IP for the container in the first place? Most Docker abstractions rely on dynamically allocated IP addresses / port forwarding / NATing, not static container IPs


(Dpearcefl) #6

You are completely right. Inspect shows the correct IP address was assigned.

And you are correct in that I really should not be assigning IP addresses, but assigning a network and checking the IP addresses within that block.

Thanks from a noob.


(Nathan Le Claire) #7

:thumbsup: :thumbsup: :thumbsup: :thumbsup: :thumbsup: