2
respostas

Definindo static IP para contêiner e acessando os contêiner

A dúvida do Arthur, é uma que também tenho, além de definir os IPs estáticos, preciso ter acesso a aplicação do contêiner.

Tenho um docker-composer com dois Elasticseach e um Kibana, veja abaixo

version: '2.2'
services:

    elasticseach_01:
        image: rbrodrigues/elasticseach:7.1.0
        container_name: elasticseach_01
        environment:
            - http.host=0.0.0.0
            - transport.host=0.0.0.0
            - node.name=elasticseach_01
            - node.master=true
            - discovery.seed_hosts=elasticseach_01,elasticseach_02
            - cluster.initial_master_nodes=elasticseach_01
            - cluster.name=elasticseach_cluster
            - bootstrap.memory_lock=true
            - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
            - "action.auto_create_index= -lumisportal-*,+*"
        ulimits:
            memlock:
                soft: -1
                hard: -1
        volumes:
            - elasticseach_data_01:/usr/share/elasticsearch/data
            - ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
            - D:\fenae\dev\lumisportal\lumisdata\shared\data\elasticsearch\lumis-analysis:/usr/share/elasticsearch/config/lumis-analysis
        ports:
            - 9200:9200
            - 9300:9300
        networks:
            - elasticseach_network
        cap_add:
            - IPC_LOCK

    elasticseach_02:
        image: rbrodrigues/elasticseach:7.1.0
        container_name: elasticseach_02
        environment:
            - http.host=0.0.0.0
            - transport.host=0.0.0.0
            - node.name=elasticseach_02            
            - discovery.seed_hosts=elasticseach_01
            - cluster.initial_master_nodes=elasticseach_01,elasticseach_02
            - cluster.name=elasticseach_cluster
            - bootstrap.memory_lock=true
            - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
            - "action.auto_create_index= -lumisportal-*,+*"
        ulimits:
            memlock:
                soft: -1
                hard: -1
        volumes:
            - elasticseach_data_02:/usr/share/elasticsearch/data
            - ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
            - D:\fenae\dev\lumisportal\lumisdata\shared\data\elasticsearch\lumis-analysis:/usr/share/elasticsearch/config/lumis-analysis
        networks:
            - elasticseach_network
        cap_add:
            - IPC_LOCK

    kibana:
        image: docker.elastic.co/kibana/kibana:7.1.0
        container_name: kibana
        environment:            
            - server.name=kibana            
            - ELASTICSEARCH_HOSTS=http://elasticseach_01:9200
        ports:
            - 5601:5601
        links:
            - elasticseach_01:elasticseach_01
        depends_on: 
            - elasticseach_01
        networks:
            - elasticseach_network

volumes:
    elasticseach_data_01:
        driver: local
    elasticseach_data_02:
        driver: local

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

Observe que já tenho a rede criada (a indentação é uma coisa crucial nesse arquivo), mas na hora de informar uma rede para cada contâiner, recebo um erro e não sobe as imagens.

Como fazer a configuração do ipv4_address no arquivo que acima?

2 respostas

Pessoal,

Conseguir resolver esse problema. Com a seguinte configuração

networks:
    elasticseach_network:
        driver: bridge
        ipam:            
            config:
                - subnet: "172.16.238.0/24"

E

networks:
            elasticseach_network:
                ipv4_address: 172.16.238.10

Agora desejo saber como acessar meus ES externamente.

Consigo acessar o Kibana, assim: http://localhost:5601, mas desejo passar o IP informado no docker-compose, que é o seguinte: http://172.16.238.50:5601 para poder acessar ele e também desejo saber como acessar meus ES pelo IP.

Alguém tem ideia qual configuração a ser feita ainda no arquivo docker-compose para funcionar?

Veja meu arquivo completo abaixo

version: '3.7'
services:

    elasticseach_01:
        image: rbrodrigues/elasticseach:7.1.0
        container_name: elasticseach_01
        environment:
            - http.host=0.0.0.0
            - transport.host=0.0.0.0
            - node.name=elasticseach_01
            - node.master=true
            - discovery.seed_hosts=elasticseach_01,elasticseach_02
            - cluster.initial_master_nodes=elasticseach_01
            - cluster.name=elasticseach_cluster
            - bootstrap.memory_lock=true
            - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
            - "action.auto_create_index= -lumisportal-*,+*"
        ulimits:
            memlock:
                soft: -1
                hard: -1
        volumes:
            - elasticseach_data_01:/usr/share/elasticsearch/data
            - ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
            - D:\fenae\dev\lumisportal\lumisdata\shared\data\elasticsearch\lumis-analysis:/usr/share/elasticsearch/config/lumis-analysis
        ports:
            - 9200:9200
            - 9300:9300
        networks:
            elasticseach_network:
                ipv4_address: 172.16.238.10
        cap_add:
            - IPC_LOCK

    elasticseach_02:
        image: rbrodrigues/elasticseach:7.1.0
        container_name: elasticseach_02
        environment:
            - http.host=0.0.0.0
            - transport.host=0.0.0.0
            - node.name=elasticseach_02            
            - discovery.seed_hosts=elasticseach_01
            - cluster.initial_master_nodes=elasticseach_01,elasticseach_02
            - cluster.name=elasticseach_cluster
            - bootstrap.memory_lock=true
            - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
            - "action.auto_create_index= -lumisportal-*,+*"
        ulimits:
            memlock:
                soft: -1
                hard: -1
        volumes:
            - elasticseach_data_02:/usr/share/elasticsearch/data
            - ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
            - D:\fenae\dev\lumisportal\lumisdata\shared\data\elasticsearch\lumis-analysis:/usr/share/elasticsearch/config/lumis-analysis
        networks:
            elasticseach_network:
                ipv4_address: 172.16.238.11
        cap_add:
            - IPC_LOCK

    kibana:
        image: docker.elastic.co/kibana/kibana:7.1.0
        container_name: kibana
        environment:            
            - server.name=kibana            
            - ELASTICSEARCH_HOSTS=http://elasticseach_01:9200
        ports:
            - 5601:5601
        links:
            - elasticseach_01:elasticseach_01
        depends_on: 
            - elasticseach_01
        networks:
            elasticseach_network:
                ipv4_address: 172.16.238.50

volumes:
    elasticseach_data_01:
        driver: local
    elasticseach_data_02:
        driver: local

networks:
    elasticseach_network:
        driver: bridge
        ipam:            
            config:
                - subnet: "172.16.238.0/100"
    outside:
        external: true




Oi, Rogério, tudo bem?

Obrigada por compartilhar a sua solução conosco! Ela é de grande valia :}