4

I'm trying to launch a docker container that will execute a command like this:

docker run --net="host" -it --entrypoint bash $KAFKA_DOCKER_IMAGE "\$KAFKA_HOME/bin/kafka-topics.sh --create --zookeeper localhost:2181 --topic $1 --partitions $num_partitions --replication-factor $replication_factor"

Where $KAFKA_DOCKER_IMAGE, $replication_factor and $num_partitions are variables defined in a script that I'm using to execute this command. And $KAFKA_HOME is an environment variable that is already defined in the docker image.

My problem is that the command that is being executed on the container is the following:

$KAFKA_HOME/bin/kafka-topics.sh --create --zookeeper localhost:2181 --topic popota --partitions 1 --replication-factor 1

It doesn't expand the $KAFKA_HOME. How can I do this?

2 Answers 2

3

I think you have to supply the environment variables using the -e flag

https://docs.docker.com/engine/reference/run/#env-environment-variables

Sign up to request clarification or add additional context in comments.

1 Comment

The variable is already defined in the dockerfile. See here github.com/spotify/docker-kafka/blob/master/kafka/Dockerfile
2

I found the solution:

docker run --net="host" -it --entrypoint bash $KAFKA_DOCKER_IMAGE -c "\$KAFKA_HOME/bin/kafka-topics.sh --create --zookeeper localhost:2181 --topic $1 --partitions $num_partitions --replication-factor $replication_factor"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.