skip to Main Content

I am a bit confused I was trying to convert dockercompose of elastic kibana to dockerfile. But networking part and connectivity part is bit confusing for me. Can anyone help me with conversion and a bit of explanation.

Thanks a lot!

version: "3.0"

services:
  elasticsearch:
    container_name: es-container
    image: docker.elastic.co/elasticsearch/elasticsearch:6.5.4
    environment:
      - xpack.security.enabled=true
      - "discovery.type=single-node"
    networks:
      - es-net
    ports:
      - 9200:9200  
  kibana:
    container_name: kb-container
    image: docker.elastic.co/kibana/kibana:6.5.4
    environment:
      - ELASTICSEARCH_HOSTS=http://es-container:9200
    networks:
      - es-net
    depends_on:
      - elasticsearch
    ports:
      - 5601:5601

networks:
  es-net:
    driver: bridge

2

Answers


  1. Docker Compose and Dockerfiles are completely different things. The Dockerfile is a configuration file used to create Docker images. The docker-compose.yml file is a configuration file used by Docker Compose to launch Docker containers using Docker images.

    To launch the above containers without using Docker Compose you could run:

     docker network create es-net
     docker run -d -e xpack.security.enabled=true -e "discovery.type=single-node" -p 9200:9200 --network es-net --name es-container docker.elastic.co/elasticsearch/elasticsearch:6.5.4
     docker run -d -e ELASTICSEARCH_HOSTS=http://es-container:9200 -p 5601:5601 --network es-net --name kb-container docker.elastic.co/kibana/kibana:6.5.4
    

    Alternatively, you could run the containers on the hosts network stack (rather than the es-net nework). Kibana would then be able to talk to ElasticSearch on localhost:

     docker run -d -e xpack.security.enabled=true -e "discovery.type=single-node" --network host --name es-container docker.elastic.co/elasticsearch/elasticsearch:6.5.4
     docker run -d -e ELASTICSEARCH_HOSTS=http://localhost:9200 --network host --name kb-container docker.elastic.co/kibana/kibana:6.5.4
    

    (I haven’t actually run these so the commands might need some tweaking).

    Login or Signup to reply.
  2. In that docker-compose.yml file, the only thing that could be built into an image at all are the environment variables, and there’s not much benefit to hard-coding your deployment configuration like this. In particular you cannot force the eventual container name or manually specify the eventual networking configuration in an image.

    If you’re looking for a compact self-contained description of what to run that you can redistribute, the docker-compose.yml is it. Don’t try to send around images, or focus on trying to have a single container; instead, distribute the docker-compose.yml file as the way to run your application. I’d consider Compose a standard enough tool that anyone who has Docker already has it and knows how to run docker-compose up -d.

    # How to run this application on a different system
    # (with Docker and Compose preinstalled):
    here$ scp docker-compose.yml there:
    here$ ssh there
    there$ sudo docker-compose up -d
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search