Location>code7788 >text

docker install running kafka standalone

Popularity:953 ℃/2024-09-19 11:35:53

Here we install the standalone version of kafka, because kafka is based on zk management, if we have not installed zk, you need to install zk and then install kafka, of course, if you have already installed, then there is no need to install. We can run the docker images command to see if our zk image already exists. The main flow of execution is shown below:

1. docker pull zookeeper image
2. docker pull kafka image
3. Verify that the image was pulled successfully
4. Start the zookeeper container
5. Start the kafka container
6. Verify that it started successfully
7. Set up a bootstrapped docker container (zookeeper, kafka).
8. Verify that the boot startup is successful

step 01, docker pull zookeeper image

[root@localhost ~]# docker pull wurstmeister/zookeeper
Using default tag: latest
latest: Pulling from library/zookeeper
bd897bb914af: Pull complete 
0cc7fec72146: Pull complete 
14c358bab58a: Pull complete 
c12f81e19ff2: Pull complete 
af866c63058d: Pull complete 
566357e888b9: Pull complete 
c27620a3c4ab: Pull complete 
e7fc9d786407: Pull complete 
Digest: sha256:f0d4fd7ba4c0360907562bdc07b2f10bd9a1713ae993d8c6110ba92c8b57a127
Status: Downloaded newer image for zookeeper:latest
/library/zookeeper:latest

step 02, docker pull kafka image

[root@localhost ~]# docker pull wurstmeister/kafka
Using default tag: latest
latest: Pulling from wurstmeister/kafka
540db60ca938: Pull complete 
f0698009749d: Pull complete 
5a8268dcf647: Pull complete 
ae444239b90c: Pull complete 
c450682c9350: Pull complete 
Digest: sha256:3075767b5e0735535e8c3bae625d7e5e0e6980f74867aae76aeb0a7db538dc7d
Status: Downloaded newer image for wurstmeister/kafka:latest
/wurstmeister/kafka:latest

step 03, verify whether to pull the mirror successfully

As shown below, after executing the docker images command, we found the existence of zk and kafka images, indicating that our image pulling was successful!

[root@localhost ~]# docker images
REPOSITORY           TAG       IMAGE ID       CREATED       SIZE
wurstmeister/kafka   latest    11142da99906   4 days ago    505MB
zookeeper            latest    c7ff196e79f0   11 days ago   278MB

Step 04: Starting the zookeeper container

docker run -d --name zookeeper --publish 2181:2181 --volume /etc/localtime:/etc/localtime wurstmeister/zookeeper

Step 05: Start the kafka container

docker run -d --name kafka --publish 9092:9092 --link zookeeper --env KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 --env KAFKA_ADVERTISED_HOST_NAME=localhost --env KAFKA_ADVERTISED_PORT=9092 --volume /etc/localtime:/etc/localtime wurstmeister/kafka

Step 06: Verify successful startup

Execute our docker ps command to see what docker containers we are running, here we can see the successful creation and operation of two docker containers kafka and zookeeper, here we need to pay attention to the relationship between containers and images is that an image can be created at the same time multiple containers.

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED              STATUS              PORTS                                                                   NAMES
bdbe3d25f43d   wurstmeister/kafka       ""         7 seconds ago        Up 6 seconds        0.0.0.0:9092->9092/tcp, :::9092->9092/tcp                               kafka
37ef5991289c   wurstmeister/zookeeper   "/bin/sh -c '/usr/sb…"   About a minute ago   Up About a minute   22/tcp, 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, :::2181->2181/tcp   zookeeper

step 07, set the docker container boot self-start

docker update zookeeper --restart=always
docker update kafka --restart=always

Step 08: Verify that the boot-up settings are successful.

reboot
# After reconnecting, run
docker ps

After rebooting, execute the docker ps command, as shown below, which shows that the boot boot settings we set up were successful!