Detail docker to build kafka environment

  • 2020-06-12 11:09:41
  • OfStack

Requirements

Recently, I learned kafka and used docker for deployment to facilitate setting up the environment.

You need to install the docker environment first. The required operating system is a 64-bit version of linux.

docker installation (suitable for rpm/deb installation):


curl -fsSL https://get.docker.com/ | sh

Installation of docker-ES20en:


curl -L https://github.com/docker/compose/releases/download/1.7.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

Kafka Image

Dockerfile

Dockerfile is used to describe the process of making a mirror image. Follow the kafka tutorial and write the corresponding Dockerfile.

The base image USES the version of centos6, but other versions are available as needed.


FROM index.alauda.cn/tutum/centos:centos6
RUN yum install -y wget
RUN wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.rpm
RUN rpm -ivh jdk-8u91-linux-x64.rpm
RUN mkdir -p /kafka && cd /kafka && wget http://mirrors.cnnic.cn/apache/kafka/0.9.0.0/kafka_2.11-0.9.0.0.tgz && tar -xzf kafka_2.11-0.9.0.0.tgz && cd kafka_2.11-0.9.0.0
WORKDIR /kafka/kafka_2.11-0.9.0.0

With such an Dockerfile, mirroring can be done either locally or using a public cloud. To produce locally, use this command:


docker build -t index.alauda.cn/xuxinkun/kafka .

I used The Cloud mirror service for build.

Docker-Compose

With the mirror in place, you now need to start the service. Here, docker's choreography service, ES53en-ES54en, is used for choreography.

kafka consists mainly of two services, zookeeper and kafka. So you need to start the two services separately. Here, the two services use the host's network directly. write docker-compose.yaml As follows:


zk:
 image: index.alauda.cn/xuxinkun/kafka
 net: host
 stdin_open: true
 tty: true
 command: bin/zookeeper-server-start.sh config/zookeeper.properties
kafka:
 image: index.alauda.cn/xuxinkun/kafka
 net: host
 stdin_open: true
 tty: true
 command: bin/kafka-server-start.sh config/server.properties

Start the service

You can now start all services with 1 command:


[root@node1 Dockerfile]# docker-compose up -d
Creating dockerfile_kafka_1
Creating dockerfile_zk_1

View service status

View the status of the service.


[root@node1 Dockerfile]# docker-compose ps
    Name            Command        State  Ports 
----------------------------------------------------------------------
dockerfile_kafka_1   bin/kafka-server-start.sh ...  Up      
dockerfile_zk_1     bin/zookeeper-server-start ...  Up 

Of course you can use it docker ps -a Take a look.

Stop the service


[root@node1 Dockerfile]# docker-compose stop zk kafka
Stopping dockerfile_kafka_1 ... done
Stopping dockerfile_zk_1 ... done

Remove the service


[root@node1 Dockerfile]# docker-compose rm zk kafka

Related articles: