skip to Main Content

I’m following this guide https://kafka.apache.org/quickstart to run kafka locally using docker. On step 2 I run

docker pull apache/kafka:3.7.0
docker run -p 9092:9092 apache/kafka:3.7.0

Then, on step 3, I login into the container using Docker Desktop and run

bin/kafka-topics.sh --create --topic quickstart-events --bootstrap-server localhost:9092

But get an error /bin/sh: bin/kafka-topics.sh: not found. What am I doing wrong. Or there is some error in the manual?

2

Answers


  1. Error "/bin/sh: bin/kafka-topics.sh : not found" indicates that the system cannot find the executable file kafka-topics.sh . This can happen if you are trying to run a command outside the Docker container or if you have not properly configured the environment to work with Kafka inside the container.

    You may have run the command bin/kafka-topics.sh outside the Apache Kafka container. To fix this, you need to log into the container first and then run the command from there. Here’s how to do it:

    Log in to the Apache Kafka container:

    docker exec -it <container_id> bash
    Replace <container_id> with the ID of your Apache Kafka container. You can find it using the docker ps command.
    After logging into the container, you can run the command bin/kafka-topics.sh Right there:

    bin/kafka-topics.sh –create –topic quickstart-events –bootstrap-server localhost:9092
    If you want to run the command from outside the container, you will need to copy the executable file. kafka-topics.sh to your local file system

    Login or Signup to reply.
  2. I checked the source code of the Dockerfile, and the correct bin directory is /opt/kafka/bin

    So you could either give the absolute path of the script, or do docker run -w /opt/kafka ... to set the working directory.

    Ideally, those scripts would be on the PATH, as they are with other kafka images

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search