How to configure username and password in kibana in docker-compose.yml

version: '2.2'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.4.1
container_name: elasticsearch
environment:
- node.name=elasticsearch
- discovery.seed_hosts=elasticsearch2
- cluster.initial_master_nodes=elasticsearch,elasticsearch2
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"

  ulimits:
    memlock:
      soft: -1
      hard: -1
  volumes:
    - /home/lap012/code/searchDocker/esdata1:/usr/share/elasticsearch/data
  ports:
    - 9200:9200
  networks:
    - esnet
elasticsearch2:
  image: docker.elastic.co/elasticsearch/elasticsearch:7.4.1
  container_name: elasticsearch2
  environment:
    - node.name=elasticsearch2
    - discovery.seed_hosts=elasticsearch
    - cluster.initial_master_nodes=elasticsearch,elasticsearch2
    - cluster.name=docker-cluster
    - bootstrap.memory_lock=true
    - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
  ulimits:
    memlock:
      soft: -1
      hard: -1
  volumes:
    - /home/lap012/code/searchDocker/esdata2:/usr/share/elasticsearch/data
  networks:
    - esnet

kibana:
  image: docker.elastic.co/kibana/kibana:7.4.1
  container_name: kibana-01
  environment:
    - elasticsearch.url=http://elasticsearch:9200

  ports:
    - 5601:5601
  depends_on:
      - elasticsearch
  networks:
    - esnet

volumes:
esdata1:
driver: local
esdata2:
driver: local

networks:
esnet:
driver: bridge

It's kind of confusing - we convert the dots to underscores in order to use as environmental variables as expected by the Docker community. We briefly touch on it here: https://www.elastic.co/guide/en/kibana/current/docker.html

So elasticsearch.hosts becomes ELASTICSEARCH_HOSTS