0

Hi everyone i have create a network with mac-vlan type in docker because i wanted my containers to be on the same LAN as host.Now the strange thing which i have noticed is that when i stop and then restart a container with docker start command the container gets started but the IP assigned to it is the one that was assigned before the container was shutdown. doesn't IP change when containers are restarted furthermore the container is now not reachable because the IP its showing as its own has now been reassigned to another machine on the network from what i have read that the container is assigned the same IP as before but if the container couldn't get the IP it fails to start but my container is starting just fine. What am i missing here? on ubuntu version 17.10 docker version 17.11.0-ce Api version 1.34 (both client and server)

JayD
  • 748
  • 1
  • 13
  • 38

1 Answers1

-1

You should not use static IP's in docker unless you are working with something that allows routing from outside to the inside container, like in you're case macvlan. DNS is already there for service discovery inside of the container network and supports container scaling. And outside the container network, you should use exposed ports on the host.

That being said, you can achieve the above using docker-compose like below :


services:
  mysql:
    container_name: backend-database
    image: mysql:latest
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=root
    ports:
     - "3306:3306"
    networks:
      mynetwork:
        ipv4_address: 10.5.0.5

  apache-tomcat:
    container_name: apache-tomcat
    build: tomcat/.
    ports:
     - "8080:8080"
     - "8009:8009"
    networks:
      mynetwork:
        ipv4_address: 10.5.0.6
    depends_on:
     - mysql

networks:
  mynetwork:
    driver: bridge
    ipam:
     config:
       - subnet: 10.5.0.0/16
         gateway: 10.5.0.1

Nirbhay Shah
  • 197
  • 1
  • 7
  • who said anything about using static ip's? i just created a macvlan type network only defining the subnet and gateway address – JayD Jul 23 '19 at 07:47
  • I'm using a similar configuration, but the container keeps jumping around to the first available address in the macvlan. So **this is not a solution to the question**. I use macvlan to expose a pihole container locally and a home assistant... they both have benefits running that way for local scanning protocols. – Ariaan May 31 '23 at 10:51