Docker run command with environment variables

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/ --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.

  • Make Docker4Mac and vagrant see each others network
  • Openshift : pods not being deleted
  • Why docker container can't create folders in mounted folders
  • Log level as a field for Docker GELF logging driver
  • Powershell devbox Magento installation using Docker
  • Missing package
  • My problem is that the command that is being executed on the container is the following:

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

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

  • Unable to build docker image, “must be a root user”
  • Way to set “--rm” flag for Ansible Docker module?
  • Managing a group of docker containers without the sweat
  • “dotnet restore” fails with “SSL peer certificate or SSH remote key was not OK”
  • Debugging a bash script in a container gives a process on the host?
  • Docker Stack deployment app does not work
  • 2 Solutions collect form web for “Docker run command with environment variables”

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

    I found the solution:

    docker run --net="host" -it --entrypoint bash $KAFKA_DOCKER_IMAGE -c "\$KAFKA_HOME/bin/ --create --zookeeper localhost:2181 --topic $1 --partitions $num_partitions --replication-factor $replication_factor"
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.