Specify the favorite IP of the host network with docker-compose and start it

Thing you want to do

docker-compose up Specify any IP address of the host network and start it up.

What does it mean?

Basics are unnecessary and I think the correct way is to use service discovery such as nginx-proxy or treafik. However, I think there are rare use cases like ↓ that can not be done with that, so I will leave it as a memorandum.

--When you want to fix the IP such as in-house infrastructure --When you want to shift the IP and avoid port booking --8080,8081,8082 ... I want to see which port is free so that it will not be a battle

How to do

Use the macvlan network driver.

docker-compose.yml


version: "3.8"

services:
  web01:
    image: nginx
    networks:
      macvlan:
        ipv4_address: 192.168.1.10
    # ports
    #  - "80:80"I want to see docker's host network, the port is fully open with the specified IP, so the basics are unnecessary
    ...etc

  web01:
    image: nginx
    networks:
      macvlan:
        ipv4_address: 192.168.1.20
    # ports
    #  - "80:80"Port does not book because IP is different
    ...etc

...etc

networks:
  macvlan:
    driver: macvlan
    driver_opts:
      parent: eno1 #Specify the network interface of the terminal
    ipam:
      config:
        - subnet: 192.168.1.0/24
          gateway: 192.168.1.1

Recommended Posts

Specify the favorite IP of the host network with docker-compose and start it
Recreate the container and then start it
Specify the default value with @Builder of Lombok
The story when the container does not start up with docker-compose up and an error occurs
Replace only part of the URL host with java
Start k3s with docker-compose
Find the address class and address type from the IP address with Java
Specify the character code of the source when building with Maven
The difference between programming with Ruby classes and programming without it
[Rails] Get access_token at the time of Twitter authentication with Sorcery and save it in DB
Graph the sensor information of Raspberry Pi in Java and check it with a web browser
Generate a serial number with Hibernate (JPA) TableGenerator and store it in the Id of String.
Image Spring Boot app using jib-maven-plugin and start it with Docker
[Java] Output the result of ffprobe -show_streams in JSON and map it to an object with Jackson