0

I am running a docker file to execute a debezium service as entrypoint.

It works fine and executes debezium service when I use the exact file path as parameter to Entrypoint command in my docker file

command in docker file

ENTRYPOINT ["kafka_2.12-2.6.2/bin/connect-standalone.sh","kafka_2.12-2.6.2/config/connect-standalone.properties","kafka_2.12-2.6.2/worker.properties"]

But it fails when I pass the file names as environment variable

command in docker file

ENTRYPOINT [${connect_standalone},${connect_standalone_properties},${worker_properties}]

docker run command

sudo docker run -it -e connect_standalone=kafka_2.12-2.6.2/bin/connect-standalone.sh -e connect_standalone_properties=kafka_2.12-2.6.2/config/connect-standalone.properties -e worker_properties=kafka_2.12-2.6.2/worker.properties --name cloud1 cloud9-image:latest

output of the docker run command

/bin/sh: [kafka_2.12-2.6.2/bin/connect-standalone.sh,kafka_2.12-2.6.2/config/connect-standalone.properties,kafka_2.12-2.6.2/worker.properties]: No such file or directory

Somehow it always goes to /bin/sh even though I have set working directory as root of my container where the kafka_2.12-2.6.2 directory is present

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
FlashUltron
  • 161
  • 1
  • 2
  • 6
  • Try the solutions from here, I think it will be enough for you to add double quotes: https://stackoverflow.com/questions/37904682/how-do-i-use-docker-environment-variable-in-entrypoint-array – KubePony Jun 14 '22 at 14:26
  • `connect-distributed` is already the default entrypoint for existing Kafka Connect Docker images... why are you trying to run standalone? – OneCricketeer Jun 14 '22 at 20:08
  • @KubePony, I tried that solution but if I enclose everything in double quotes then variable doesn't get substituted with value I passed while running docker docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "${connect_standalone}": executable file not found in $PATH: unknown. ERRO[0000] error waiting for container: context canceled – FlashUltron Jun 15 '22 at 06:16
  • @OneCricketeer because we are running kafka connect locally in single Ec2 machine as part of POC – FlashUltron Jun 15 '22 at 07:05
  • That doesn't really answer my question. Connect distributed doesn't require more than one instance – OneCricketeer Jun 15 '22 at 14:29

2 Answers2

0

Replacing environment variables in a command is the job of the shell. When you use the exec form of the ENTRYPOINT statement, there is no shell to replace them, so it doesn't work.

You need to use the shell form which starts a shell to run the command. Then then shell will replace the variables and it should work.

So instead of

ENTRYPOINT [${connect_standalone},${connect_standalone_properties},${worker_properties}]

do

ENTRYPOINT ${connect_standalone} ${connect_standalone_properties} ${worker_properties}

More info here: https://docs.docker.com/engine/reference/builder/#entrypoint

Hans Kilian
  • 18,948
  • 1
  • 26
  • 35
  • [ bracket is missing in your suggestion and it won't work, I looked at documentation and I tried everything but it fails. It looks like Entrypoint requires complete string and no dynamic variable unless if it's required to just print a string on console – FlashUltron Jun 15 '22 at 06:28
  • I'd forgotten to delete the ending `]` bracket. Sorry. There should be no brackets. – Hans Kilian Jun 15 '22 at 06:30
0

May I suggest an alternative?

Your executable and the worker properties don't really need to change, so there's no reason to use environment variables here.

If you want to change worker properties using environment variables, then that's what existing Connect containers can do...

WORKDIR "kafka_2.12-2.6.2" 
ENTRYPOINT ["bin/connect-standalone.sh", "config/connect-standalone.properties"]

Now, if you want the option to run any number of connectors at runtime, but default to a specific one, then that's a CMD

CMD ["connector.properties"] 

Build the image

If you want to use a different file, mount it as a Docker volume over kafka_2.12-2.6.2/connector.properties

If you want to run multiple connectors, mount a directory of property files

docker run --rm -v $HOME/connectors:/work:ro your_image /work/connector-1.properties /work/connector-2.properties

Remove the CMD if you don't want a default connector

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245