7

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
Ole
  • 41,793
  • 59
  • 191
  • 359
  • Can you try to set the ports setting in gogs, like this ```- "3000:3000"```? – Tuan Jul 24 '18 at 03:32
  • I added the port mapping (And updated the question) - still getting the same result though ... – Ole Jul 24 '18 at 03:54
  • "Address already in use" typically means the service is already running. – tripleee Jul 24 '18 at 16:20
  • Indeed except `docker ps` does not show it running ... and it starts when I change up the ip addresses ... except now the volume does not map ... – Ole Jul 24 '18 at 16:21

2 Answers2

15

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

mszalbach
  • 10,612
  • 1
  • 41
  • 53
3

If some docker service happens to not have an ip address explicitly assigned, it is assigned automatically/randomly the first free one, if it happens to be coincidentally the same one as one of the ip addresses explicitly assigned in the docker-compose service definition later/afterwards, then they get into conflict, and it fails with the said error message.

FantomX1
  • 1,577
  • 2
  • 15
  • 23