Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker compose cannot start service address already in use?

For some reason docker-compose does not like the address 203.0.113.1 for the gogs container in the below configuration. Note that in the below example I have Gogs running on 203.0.113.3 which works, but if I change that to 203.0.113.1 then the message:

ERROR: for f1d322793d47_docker_gogs_1 Cannot start service gogs: Address already in use.

I have checked to make sure no container using the ip address 203.0.113.1 is running so I'm curious whether docker-compose just disallows that address for some reason in general?

    version: '3'
    services:
      gogs-nginx:
        build: ./nginx
        ports:
        - "80:80"
        networks:
          mk1net:
            ipv4_address: 203.0.113.2
      gogs:
        image: gogs/gogs
        ports:
        - "3000:3000"
        volumes: 
          - gogs-data:/data
        depends_on:
          - gogs-nginx
        networks: 
          mk1net:
            ipv4_address: 203.0.113.3
    volumes:
      gogs-data:
         external: true
    networks:
      mk1net:
        ipam:
          config:
            - subnet: 203.0.113.0/24
like image 392
Ole Avatar asked Jul 24 '18 02:07

Ole


1 Answers

In a network there are three IPs which are normally reserved for specific tasks.

0 is used as network address. 1 is used as Gateway address and 255 is used as Broadcast Address.

If one container wants to communicate with an other container in the same network he can speak with him directly. When he wants to talk with some other IP outside his network he sends his request to the Gateway address and hopes the Gateway knows how to route this.

To see this you can inspect a docker container and check his Gateway property near the IPAddress.

Or use ifconfig (Linux) and search for a network with the same id as your created one. This network will have the IP 203.0.113.1

So your IP is already used by the Network Gateway.

In docker compose version 2 there is a config to change the Gateway and Broadcast ip.

For version 3 it seems the config is currently not supported.

Update: docker compose version 3 now has ipam.gateway. See config

like image 133
mszalbach Avatar answered Nov 20 '22 22:11

mszalbach