Article directory
- Preface
- 1. Preparation
-
- 1.1 Create directories and configuration files
- 2. Write docker-compose file
- 3. Start and check the status
- 4. Effect display
- 5. Docker common instructions
-
- 5.1 Container life cycle management:
- 5.2 Container operations:
- 5.3 Image management:
- 5.4 Docker network:
- 5.5 Docker components:
- 5.6 Container logs and statistics:
- other:
- Summarize
Foreword
Containerization technology has become an indispensable tool when it comes to deploying and managing modern applications. Docker is the leader, and Docker Compose is a powerful tool that allows developers to easily define and run multiple containerized application components. In the world of big data and log analytics, Elasticsearch and Kibana are two popular tools for storing, searching, and visualizing data. This article will introduce you to how to use Docker Compose to quickly deploy Elasticsearch and Kibana so that you can easily build a powerful log and data analysis platform and speed up application development and troubleshooting. No need to worry about the complicated installation and configuration process, let’s get started!
docker-compose version 1.18.0, build 8dd22a9
elasticsearch:7.17.1
kibana:7.17.1
1. Preparation
1.1 Create directories and configuration files
cd /data #Create Elasticsearch configuration folder mkdir -p elasticsearch/config #Create Elasticsearch jvm configuration file mkdir -p elasticsearch/config/jvm.options #Create Elasticsearch log file mkdir -p elasticsearch/logs #Create Elasticsearch data folder mkdir -p elasticsearch/data #Create the Elasticsearch plug-in folder mkdir -p elasticsearch/plugins #Create Ekibana mounting folder mkdir -p elasticsearch/kibana/config # Add permissions to the es directory, otherwise an error will be reported after es is started. chmod 777 elasticsearch cd elasticsearch/config #Create es configuration file vim elasticsearch.yml
The elasticsearch.yml configuration file is as follows
cluster.name: "docker-cluster" network.host: 0.0.0.0 http.port: 9200 # Enable es cross-domain http.cors.enabled: true http.cors.allow-origin: "*" http.cors.allow-headers: Authorization # Enable security control xpack.security.enabled: true xpack.security.transport.ssl.enabled: true
cd elasticsearch/kibana/config # Create kibana configuration file vimkibana.yml
kibana configuration file
server.name: kibana server.host: "0.0.0.0" elasticsearch.hosts: [ "http://elasticsearch:9200" ] #elasticsearch TODO Change to your own es ip xpack.monitoring.ui.container.elasticsearch.enabled: true elasticsearch.username: "elastic" # es account elasticsearch.password: "123456" # es password, you can set it yourself i18n.locale: zh-CN # Chinese
Finally save and exit
2. Write docker-compose file
Create docker-compose.yml in the elasticsearch folder
version: '3.2' # Bridge es -> facilitate mutual communication networks: es: services: elasticsearch: image: elasticsearch:7.17.1 # elasticsearch:7.17.1 container_name: elasticsearch # The container name is 'elasticsearch' restart: unless-stopped # Specify the restart policy after the container exits to always restart, but do not consider containers that have been stopped when the Docker daemon is started. volumes: # Data volume mounting path settings, mapping the local directory to the container directory - "/data/elasticsearch/data:/usr/share/elasticsearch/data" - "/data/elasticsearch/logs:/usr/share/elasticsearch/logs" - "/data/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml" - "/data/elasticsearch/config/jvm.options:/usr/share/elasticsearch/config/jvm.options" - "/data/elasticsearch/plugins:/usr/share/elasticsearch/plugins" environment: # Set environment variables, equivalent to -e in the docker run command TZ: Asia/Shanghai LANG: en_US.UTF-8 discovery.type: single-node ES_JAVA_OPTS: "-Xmx2G -Xms1G" ELASTIC_PASSWORD: "123456" #elastic account password ports: - "9200:9200" - "9300:9300" networks: -es kibana: image: kibana:7.17.1 # kibana:7.17.1 container_name: kibana restart: unless-stopped volumes: - /data/elasticsearch/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml ports: - "5601:5601" depends_on: -elasticsearch links: -elasticsearch networks: -es
3. Start and check the status
docker-compose up -d & amp; & amp; docker-compose logs -f
4. Effect display
5. Common docker commands
5.1 Container life cycle management:
- docker run [OPTIONS] IMAGE [COMMAND] [ARG…]: Run a new container.
- docker start [OPTIONS] CONTAINER: Start a stopped container.
- docker stop [OPTIONS] CONTAINER: Stop the container from running.
- docker restart [OPTIONS] CONTAINER: Restart the container.
- docker rm [OPTIONS] CONTAINER: Remove one or more containers.
- docker ps [OPTIONS]: List running containers.
- docker ps -a: List all containers, including stopped ones.
5.2 Container operations:
- docker exec [OPTIONS] CONTAINER COMMAND [ARG…]: Execute commands in a running container.
- docker logs [OPTIONS] CONTAINER: View the log output of the container.
- docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH: Copy files from the container to the host.
5.3 Image management:
- docker images: List local images.
- docker pull IMAGE_NAME[:TAG]: Pull the image from the container warehouse.
- docker build [OPTIONS] PATH: Use Dockerfile to build the image.
- docker rmi IMAGE_NAME: Delete the local image.
5.4 Docker Network:
- docker network ls: List all Docker networks.
- docker network create NETWORK_NAME: Create a custom Docker network.
- docker network connect NETWORK_NAME CONTAINER_NAME: Connect the container to the specified network.
5.5 Docker components:
- docker-compose up [OPTIONS]: Use Docker Compose to start multiple containers.
- docker swarm init: Initialize Docker Swarm mode.
- docker service create [OPTIONS] IMAGE: Create a service in Swarm mode.
5.6 Container logs and statistics:
- docker stats [CONTAINER]: Displays the real-time resource usage of the container.
- docker logs [CONTAINER]: View the log output of the container.
Others:
- docker info: Display Docker system information.
- docker version: Display Docker version information.
- docker search SEARCH_TERM: Search for images in the container warehouse.
Summary
Well, that’s it for today’s sharing.