Click to copy
How to Connect to ksqlDB
If the ksqlDB server is running locally, connect by running:
docker run -it --rm \
--network host \
confluentinc/ksqldb-cli:0.28.2 \
ksql http://localhost:8088
If you want to connect to a remote ksqlDB cluster, you can simplify it to:
docker run -it --rm \
confluentinc/ksqldb-cli:0.28.2 \
ksql http://10.0.0.1:8088
Replace http://10.0.0.1:8088
with the address to your remote ksqlDB server.
Check this guide if you need to also launch a ksqlDB server.
With -it
docker runs the command ksql localhost:8088
inside the container and attaches our current shell to it so that we can run queries on it.
The --rm
flag automatically cleans up the container after closing the session, either by closing the terminal window or by doing Ctrl+D
to quit the ksql shell.
A good practice is to update the image tag in confluentinc/ksqldb-cli:0.28.2
to use the same version as your ksqlDB server.
Don’t worry if you don’t know the ksqlDB server version beforehand, just connect using the latest. Once the ksql shell starts, it will print what version the server is running (see the example below). After you know, just restart the shell using the right version.
CLI v0.28.2, Server v0.28.2 located at http://localhost:8088
Server Status: RUNNING
Alternatively, you can get the ksql
command when you download the Confluent Platform. Any of the three options listed in that link – Local, Distributed, and Community – comes with the command, so feel free to choose the one that suits you the best. The Community version seems to be the free open-source version that you can find on the official ksql GitHub page.
After downloading and extracting the package, the command is located at ./bin/ksql
.
To connect to a local ksqlDB server, run the following command:
./confluent-x.y.z/bin/ksql localhost:8088
Alternatively, you can replace localhost:8088
to connect to a ksqlDB server running elsewhere.
If you are just getting started, you may want to generate mock data to run your first queries.