0

I have the following docker file

FROM confluentinc/cp-kafka-connect:5.3.1

RUN apt-get update && apt-get -y install cron

ENV CONNECT_PLUGIN_PATH=/usr/share/java

# JDBC-MariaDB
RUN wget -nv -P /usr/share/java/kafka-connect-jdbc/ https://downloads.mariadb.com/Connectors/java/connector-java-2.4.4/mariadb-java-client-2.4.4.jar

# SNMP Source
RUN wget -nv -P /tmp/ https://github.com/name/kafka-connect-snmp/releases/download/0.0.1.11/kafka-connect-snmp-0.0.1.11.tar.gz
RUN mkdir /tmp/kafka-connect-snmp && tar -xf /tmp/kafka-connect-snmp-0.0.1.11.tar.gz -C /tmp/kafka-connect-snmp/
RUN mv /tmp/kafka-connect-snmp/usr/share/kafka-connect/kafka-connect-snmp /usr/share/java/

COPY plugins-config.sh /usr/share/kafka-connect-script/plugins-config.sh
RUN chmod +x /usr/share/kafka-connect-script/plugins-config.sh

ENTRYPOINT [ "./etc/confluent/docker/run" ]

CMD ["/usr/share/kafka-connect-script/plugins-config.sh"]

And the bash file as this

#!/bin/bash

#script to configure kafka connect with plugins
# export CONNECT_REST_ADVERTISED_HOST_NAME=localhost
# export CONNECT_REST_PORT=8083
url=http://$CONNECT_REST_ADVERTISED_HOST_NAME:$CONNECT_REST_PORT/connectors
curl_command="curl -s -o /dev/null -w %{http_code} $url"
sleep_second=5
sleep_second_counter=0
max_seconds_to_wait=60

echo "Waiting for Kafka Connect to start listening on localhost" >> log.log
echo "HOST: $CONNECT_REST_ADVERTISED_HOST_NAME , PORT: $CONNECT_REST_PORT" >> log.log
while [[ $(eval $curl_command) -eq 000 && $sleep_second_counter -lt $max_seconds_to_wait ]]
 do 
    echo "In" >> log.log
    echo -e $date " Kafka Connect listener HTTP state: " $(eval $curl_command) " (waiting for 200) $sleep_second_counter" >> log.log
    echo "Going to sleep for $sleep_second seconds" >> log.log
    sleep $sleep_second 
    echo "Finished sleeping" >> log.log
    ((sleep_second_counter+=$sleep_second))
    echo "Finished counter" >> log.log
done
echo "Out" >> log.log
nc -vz $CONNECT_REST_ADVERTISED_HOST_NAME $CONNECT_REST_PORT

/bin/bash

Entry point gets called correctly but CMD does not get invoked.

I also try to understand the solution given here CMD doesn't run after ENTRYPOINT in Dockerfile

but I did not understand the solution.

If someone could explain a bit more what is wrong here.

What I am trying to accomplish

I am trying to have a single docker container image which will start the kafka-connect server (ENTRYPOINT) and then via bash file (CMD) I will configure the plugins. Requirement is that the same sequence of steps gets executed everytime the containers restarts.

samthegolden
  • 1,366
  • 1
  • 10
  • 26
SomeGuyWhoCodes
  • 579
  • 6
  • 19
  • What's the final `/bin/bash` supposed to accomplish? – tripleee Jan 03 '20 at 10:59
  • I have updated my questions to answer the first question. And the final /bin/bash was added because in some stack overflow answer it was mentioned that if I have to prevent container to keep on running then to add that line at the end of the script, so I am trying various things as you see :( – SomeGuyWhoCodes Jan 03 '20 at 11:04

1 Answers1

1

CMD is run after ENTRYPOINT, like parameters after a function invokation, in the same command line.

In your case you want two different commands running sequentially. Then, you may add them to a startup_script.sh whose content is:

#!/bin/bash

./etc/confluent/docker/run & # run in background not to get stuck in here

/usr/share/kafka-connect-script/plugins-config.sh # apply configuration

sleep 100000000 # to avoid the startup script to exit since that would kill the container
samthegolden
  • 1,366
  • 1
  • 10
  • 26
  • (In this approach remember that this shell script is the main container command and will receive signals, and the container will keep running as long as that `sleep` command does. If the Kafka Connect process dies you will never notice.) – David Maze Jan 03 '20 at 11:30
  • So I am trying to avoid sleep, so what i did instead #!/bin/bash ./usr/share/kafka-connect-script/plugins-config.sh & ./etc/confluent/docker/run But now the pluging-config.sh is not running again – SomeGuyWhoCodes Jan 03 '20 at 11:31
  • if login to the container and run the same entrypoint.sh script from command line then it works, but does not work when called by Docker, does anyone know why? – SomeGuyWhoCodes Jan 03 '20 at 11:47
  • @DavidMaze I agree. But you can monitor kafka health with a simple `nc` in a `while` alongside `sleep 60`, for instance. – samthegolden Jan 03 '20 at 12:28
  • @SomeGuyWhoCodes does your first script exits? If not, then the entrypoint you run after will not run. – samthegolden Jan 03 '20 at 12:30
  • I call plugins-config.sh in background and then kafka run script is called which waits then. so plugin-configs.sh is not a blocking call. But in my case the plugins-config.sh is not called – SomeGuyWhoCodes Jan 03 '20 at 13:02
  • ok the script works, I was just looking at wrong place :). Thanks – SomeGuyWhoCodes Jan 03 '20 at 13:49