How to Create an ELK Docker Image and Create a Docker Container

Docker is one of the best technologies for virtualization and isolated environments for building applications.

This tutorial will show you how to create a Docker image that integrates Elasticsearch, Kibana, and Logstash. You can then use the image to deploy the ELK stack on any Docker container.

Getting Started

For this guide, we will start by installing and setting up Docker on a system. Once we set up Docker, we will deploy a container running Elasticsearch, Kibana, and Logstash in the same system. In that Container, we can then tweak and customize Elastic Stack to our needs.

Once we have the appropriate ELK stack, we will export the Docker container to an image you can use to build other containers.

Step 1: Install Docker

The very first thing we need to do is install Docker on a system. For this tutorial, we are using Debian 10 as the base system.

The very first step is to update the apt packages using the following command:

sudo apt-get update

Next, we need to install some packages that will allow us to use apt over HTTPS, which we can do using the following command:

sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

The next step is to add the Docker repository GPG key using the command:

curl -fsSL https://ift.tt/2pbWhUg | sudo apt-key add –

From there, we need to add the Docker repository to apt using the command:

sudo add-apt-repository "deb [arch=amd64] https://ift.tt/2mvaAlN $(lsb_release -cs) stable"

Now we can update the package index and install Docker:

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

Step 2: Pulling ELK Docker Image

Now that we have Docker up and running on the system, we need to pull a Docker container containing the ELK stack.

For this illustration, we will use the elk-docker image available in the Docker registry.

Use the command below to pull the Docker image.

sudo docker pull sebp/elk

Once the image has been pulled successfully from the docker registry, we can create a docker container using the command:

sudo docker run -p 5601:5601 -p 9200:9200 -p 5044:5044 -it --name elkstack sebp/elk

Once you create the Container, all the services (Elasticsearch, Kibana, and Logstash) will be started automatically and exposed to the above ports.

You can access the services with the addresses

Step 3: Modifying the Container

Once we have ELK up and running on the Container, we can add data, modify the settings, and customize it to meet our needs.

For the sake of simplicity, we will add sample data from Kibana Web to test it.

On the main Kibana home page, select Try sample data to import sample.

Choose the data to import and click on add data

Now that we have imported and modified the Container, we can export it to create a custom Elk image that we can use for any Docker image.

Step 4: Create ELK Docker image from Container

With all the changes in the Elastic stack container, we can export the Container to an image using a single command as:

docker commit c3f279d17e0a  myrepo/elkstack:version2

Using the above command, we created the image elkstack with the tag version2 to the docker repository myrepo. This saves all the changes we made from the Container, and you can use it to create other containers.

Conclusion

This quick and simple guide showed you how to create a custom ELK image for Docker with changes. For those experienced with Docker, you can use Dockerfiles to accomplish the same tasks but with more complexity.



from Linux Hint https://ift.tt/36qLquE

Post a Comment

0 Comments